Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Remove All Adjacent Duplicates in String II (medium)

Problem Statement

You are given a string s and an integer k. Your task is to remove groups of identical, consecutive characters from the string such that each group has exactly k characters. The removal of groups should continue until it's no longer possible to make any more removals. The result should be the final version of the string after all possible removals have been made.


    • Input: s = "abbbaaca", k = 3
    • Output: "ca"
    • Explanation: First, we remove "bbb" to get "aaaca". Then, we remove "aaa" to get "ca".
    • Input:




Like the course? Get enrolled and start learning!