200. Make the String Great (Remove Same Adjacent)

EasyStringString

Given a string s of lowercase and uppercase English letters, repeatedly remove adjacent pairs where one is the lowercase and the other is the uppercase version of the same letter (e.g., 'aA' or 'Aa' are bad pairs).

Return the resulting string after all such removals. The answer is unique.

Input: A single string s of English letters (upper and lowercase).

Output: The resulting string after removing all bad adjacent pairs.

Examples

Example 1
Input: leEeetcode
Output: leetcode
Explanation: 'eE' removed → 'leetcode'.
Example 2
Input: abBAcC
Output: 
Explanation: 'bB' removed→'aAcC'→'aA' removed→'cC'→'cC' removed→''.
Example 3
Input: s
Output: s
Explanation: Single character, no removal possible.

Constraints

Asked by

GoogleBloombergMicrosoftAmazon
Solve this problem in the editor →