Consider an operation where you choose k adjacent equal characters in s and remove them, so the part to the left and the part to the right join together.
Given that you keep performing this operation until it can no longer be performed, return the resulting string.
Note that the final string does not depend on the order in which you choose the removals. If every character is removed, return the empty string.
Examples
Example 1
Input: s = "abcd", k = 2
Output: "abcd"
Explanation: No two adjacent characters are equal, so nothing is removed.
Example 2
Input: s = "deeedbbcccbdaa", k = 3
Output: "aa"
Explanation: Remove "eee" to get "ddbbcccbdaa". Remove "ccc" to get "ddbbbdaa". Remove "bbb" to get "dddaa". Remove "ddd" to get "aa".
Example 3
Input: s = "pbbcggttciiippooaais", k = 2
Output: "ps"
Explanation: Removing "bb", "gg", "tt", and "cc" leaves "piiippooaais". Removing "ii" gives "pippooaais", then "pp" gives "piooaais", "oo" gives "piaais", "aa" gives "piis", and "ii" gives "ps".
Constraints
1≤s.length≤105
2≤k≤104
s contains only lowercase English letters.
Loading editor...
Run checks the sample cases; Submit runs every case.
Samples 3
Custom 0
passedwrong answertime limiterrorran, no expected valuenot run