Ctrl K

Case Pairs Cancel Out

Easy
You get a string text of lowercase and uppercase English letters. Whenever the same letter appears in two different cases side by side (say q and Q, in either order), that pair can be removed. Removing it brings new characters together, and this repeats until nothing more can be removed. Return the string that is left at the end. It does not depend on the order of removals; an empty string is a valid answer too.
Example 1
text='xYyz' → 'xz'

Yy is the same letter in two cases, so the pair vanishes and xz remains.

Example 2
text='kBbaAK' → ''

Bb and aA go first; then k and K end up next to each other and go as well.

Example 3
text='aa' → 'aa'

Equal letters in the same case do not cancel each other.

Constraints
  • 1 ≤ len(text) ≤ 10⁵
  • text consists only of lowercase and uppercase English letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsBracket Balance EasySame Text After Erasing EasyPeel the Outer Brackets EasyPopping Pairs EasySteps Back to the Top Folder Easy
loading Python…
Input
text='xYyz'
Expected
'xz'

Run checks the first 3 tests in your browser. Submit checks all 107 tests on the server, hidden ones included.