0% completed
Remove All Adjacent Duplicates In String (easy)
Problem Statement
You are given a string s consisting of lowercase English letters. A duplicate removal consists of choosing two adjacent and equal letters and removing them.
We repeatedly make duplicate removals on s until we no longer can.
Return the final string after all such duplicate removals have been made.
Examples
-
- Input:
s = "abccba" - Output:
"" - Explanation: First, we remove "cc" to get "abba". Then, we remove "bb" to get "aa". Finally, we remove "aa" to get an empty string.
- Input:
-
- Input:
s = "foobar" - Output:
"fbar"
- Input:
.....
.....
.....
camelBack
· 2 years ago
The question is deceiving a bit - asking for a recursive solution, while the sample answer is not a recursive answer.
Also, what about more than 2 adjacent characters? 'abcccba'?
Meghana
· 2 years ago
since all of o's are duplicates, shouldnt the answer be fbar? why is it fobar?
lejafilip
· 2 years ago
I mean at the end we use "reverse". Shouldn't we create other solution without that?
Dante Tsang
· 4 months ago
this is not monotonic