Repeatedly remove adjacent letters that are the same alphabetic character but opposite in case, until the string becomes stable.
You are given a string consisting only of English letters.
A string is considered good if it does not contain any adjacent pair of characters where:
- the two characters are the same letter, and
- one is lowercase while the other is uppercase.
In one move, you may delete any such adjacent bad pair from the string.
Keep performing deletions until no more bad pairs remain. Return the final string after all possible removals.
The order of the remaining characters must stay the same as in the original string.
Input Format
- A single string consisting of English letters only.
Output Format
- Return the string obtained after repeatedly removing all adjacent bad pairs until the string is good.
Constraints
- contains only uppercase and lowercase English letters
- The answer is unique regardless of deletion order
Example 1
Input
"leEeetcode"
Output
"leetcode"
Explanation
The substring "eE" cancels out, leaving "leetcode".
Example 2
Input
"abBAcC"
Output
""
Explanation
Each adjacent opposite-case pair can be removed until nothing remains.
Show 1 more example
Example 3
Input
"s"
Output
"s"
Explanation
A single character is already good.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.