Practice/Google/Remove Bad Pairs from a String
CodingMust
Given a string containing uppercase and lowercase English letters, repeatedly remove adjacent pairs of characters where both characters are the same letter but in opposite cases (one uppercase, one lowercase). Continue this process until no more such pairs can be removed.
For example, the pair "aA" should be removed, as should "Aa", "bB", "Bb", etc. After removing a pair, the remaining characters are concatenated, which may create new adjacent pairs that also need to be removed.
Return the final string after all possible eliminations.
Example 1:
Input: s = "aAbB" Output: "" Explanation: Remove "aA" → "bB", then remove "bB" → ""
Example 2:
Input: s = "abBA" Output: "aa" Explanation: Remove "bB" → "aBA", then remove "BA" → "aa"
Example 3:
Input: s = "leEeetcode" Output: "leetcode" Explanation: Remove "eE" → "leEtcode", then remove "eE" → "letcode", no more pairs to remove but wait - actually "letcode" has no bad pairs, but let me recalculate: "leEeetcode" → remove "Ee" → "leEtcode" → remove "eE" → "letcode". Actually reviewing: "leEeetcode" - first "Ee" at positions 2,3 → "leEtcode" → "eE" at positions 2,3 → "letcode"
Example 4:
Input: s = "aBbAcCdD" Output: "" Explanation: Multiple cascading eliminations eventually remove all characters