Disappearing Pairs
Medium
string
stack
pair-removal
simulation
Problem Description
Remove adjacent pairs of the same character from a string repeatedly until no such pairs remain. Process from left to right, and after each removal, check for new adjacent pairs.
Input Format
A single string containing lowercase letters.
Output Format
The remaining string after all possible pair removals, or empty string if nothing remains.
Constraints
• 1 ≤ string length ≤ 1000
• String contains only lowercase letters
• Remove adjacent identical pairs iteratively
• Continue until no more pairs can be removed
• Return empty string if all characters are removed
Sample Input/Output
Input:
abbaca
Output:
ca
Explanation
abbaca → aaca (remove bb) → ca (remove aa). No more adjacent pairs, result: "ca".
Solution Hints
85
Points
Points
2000ms
Time Limit
Time Limit
128MB
Memory Limit
Memory Limit
Code Editor
Register to Access Code Editor
Create a free account to solve coding problems and track your progress.
Register Now