Remove All Adjacent Duplicates in String II
You are given a string s and an integer k. A k duplicate removal consists of choosing k adjacent and equal letters from s and removing them, causing the left and right sides of the deleted substring to concatenate together.
Repeatedly make k duplicate removals on s until no more such removals can be made.
Return the final string after all such duplicate removals have been made. It is guaranteed that the answer is unique.
Example 1
Input
s = "abcd", k = 2Output
"abcd"There is nothing to delete because no two adjacent letters are equal.
Example 2
Input
s = "deeedbbcccbdaa", k = 3Output
"aa"First delete "eee" and "ccc" to get "ddbbbdaa", then delete "bbb" to get "dddaa", and finally delete "ddd" to get "aa".
Constraints
- 1 <= s.length <= 10^5
- 2 <= k <= 10^4
- s only contains lowercase English letters.