← 返回 bloomberg 的题目列表Candy Crush in 1D (Stabilize by Repeatedly Removing Groups)
类型:online_judge
Problem: 1D Candy Crush (Repeated Removal Until Stable)
Given a string s consisting of lowercase letters and an integer k.
You may repeatedly perform the following operation any number of times:
If the string contains a run of consecutive identical characters with length len >= k, remove the entire run from the string.
After removal, the left and right parts join together, possibly forming new removable runs. Continue until no more runs of length >= k exist.
Return the final stable string. If it becomes empty, output an empty line.
Input
Line 1: string s
Line 2: integer k
Output
The stable string; if empty, print an empty line.
Constraints
1 <= |s| <= 2 * 10^5
2 <= k <= 10^5
s contains only a-z
Examples
Example 1
Input:
aaabbbacd
3
Output:
acd
Example 2
Input:
abbbaa
3
Output:
Example 3
Input:
deeedbbcccbdaa
3
Output:
aa
Example
Input
aaabbbacd
3
Output
acd