Remove Adjacent Duplicates
mediumQuestion 520Write a function string removeAdjacent(const string& s) that uses a stack<char> to repeatedly delete pairs of equal adjacent characters until no such pair remains, and returns whatever is left.
Example: "abbaca" — "bb" cancels leaving "aaca", then "aa" cancels leaving "ca". The test prints the returned string on its own line (see Expected Output).
If every character cancels, return the empty string; the test then prints the line (empty).
Do NOT write a main function.
Expected output
ca ay (empty)
= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
STL ContainersStacks
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.