Skip to content
Decoder

Remove All Adjacent Duplicates In String

Easy

Problem

You get a string s of lowercase letters. A move picks two adjacent, equal letters and deletes both. Keep making moves until no more are possible, then return the final string. The final string is always the same, whatever order you make the moves in.

Example 1

Input
s = "abbaca"
Output
"ca"
Why
remove "bb" to get "aaca", then "aa" to get "ca"

Example 2

Input
s = "azxxzy"
Output
"ay"

Constraints

  • 1 <= s.length <= 10^5
  • s has only lowercase English letters.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.