P20781 [GeeksforGeeks] 8c8f95810b05b4cab665f2997d36991bd58308a2
普及
题目描述

Given a string s and an integer k, the task is to reduce the string by applying the following operation:
Choose a group of k consecutive identical characters and remove them.
The operation can be performed any number of times until it is no longer possible.
Example 1:
Input:
k = 2
s = "geeksforgeeks"
Output:
gksforgks
Explanation:
Modified String after each step:
"geeksforgeeks" -> "gksforgks"
Example 2:
Input:
k = 2
s = "geegsforgeeeks"
Output:
sforgeks
Explanation:
Modified String after each step:
"geegsforgeeeks" -> "ggsforgeks" -> "sforgeks"
Your Task:
You don't need to read input or print anything. Complete the function Reduced_String() which takes integer k and string s as input parameters and returns the reduced string.
Expected Time Complexity: O(|s|)
Expected Auxiliary Space: O(|s|)
Constraints:
1 ≤ |s| ≤ 10^{5}
1 ≤ k ≤ |s|

输入格式

见题面

输出格式

见题面

样例输入
k = 2 s = "geeksforgeeks"
样例输出
gksforgks