#K68557. Remove Adjacent Duplicates
Remove Adjacent Duplicates
Remove Adjacent Duplicates
Given a string (s) consisting of lowercase letters and an integer (k), your task is to repeatedly remove (k) adjacent and equal letters from (s) until no further removals can be performed.
For example, if (s = ) "deeedbbcccbdaa" and (k = 3), then the process of removals will eventually reduce the string to "aa".
The removal process works as follows: whenever there are (k) consecutive identical characters, they are removed from the string. The resulting string might create new contiguous groups that should be processed further. This process is repeated until no more groups of (k) adjacent identical characters remain.
inputFormat
The input consists of two lines:
1. The first line contains the string (s) (only lowercase letters).
2. The second line contains the integer (k).
outputFormat
Output the final string after all possible duplicate removals have been performed. If the final string is empty, output an empty string.## sample
abcd
2
abcd