Practice/Apple/Leetcode 1209. Remove All Adjacent Duplicates in String II
CodingMust
You are given a string s and an integer k. Your task is to repeatedly remove any sequence of exactly k consecutive identical characters from the string until no more such sequences exist.
The removal process continues until the string stabilizes—meaning no sequence of k identical consecutive characters remains. When characters are removed, the remaining parts of the string merge together, which may create new sequences of k consecutive identical characters that must also be removed.
Return the final string after all possible removals have been completed.
k consecutive identical characters in each operationk identical consecutive characters existss contains only lowercase English lettersExample 1:
` Input: s = "deeedbbcccbdaa", k = 3 Output: "aa" Explanation:
Example 2:
Input: s = "abcd", k = 2 Output: "abcd" Explanation: No character appears k=2 times consecutively, so nothing is removed
Example 3:
` Input: s = "aaabbb", k = 3 Output: "" Explanation: