Leaderboard
Showing:
Recursively remove all adjacent duplicates
Medium Accuracy: 43.24% Submissions: 9669 Points: 4

Given a string s, remove all its adjacent duplicate characters recursively. 

Example 1:

Input:
S = "geeksforgeek"
Output: "gksforgk"
Explanation: 
g(ee)ksforg(ee)k -> gksforgk​


Example 2:

Input: 
S = "acaaabbbacdddd"
Output: "acac"
Explanation: 
ac(aaa)(bbb)ac(dddd) -> acac


Your Task:
You don't need to read input or print anything. Your task is to complete the function remove() which takes the string S as input parameter and returns the resultant string.


Expected Time Complexity: O(|S|)
Expected Auxiliary Space: O(|S|)


Constraints:
1<=|S|<=105

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Recursively remove all adjacent duplicates

Output Window