Problems > Collapse Adjacent Pairs

Collapse Adjacent Pairs

Difficulty: 1300 2000 ms 128 MB

strings stack

Repeatedly delete any two equal adjacent characters until no such pair remains. Print the result, or EMPTY. The final string is unique regardless of deletion order.

Input: one line with the string S.

Output: the fully collapsed string, or EMPTY.

Constraints:

  • 1 ≤ |S| ≤ 104
  • S contains lowercase English letters

Sample Tests

Input 1
abbaca
Output 1
ca
Input 2
abba
Output 2
EMPTY

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.