Remove Adjacent Duplicate Pairs from a String

Quick Overview

Remove adjacent duplicate character pairs with a stack, handling cascading cancellations and distinguishing odd-length runs from whole-run deletion.

Remove Adjacent Duplicate Pairs from a String

Company: Whatnot

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Repeatedly remove a pair of equal adjacent characters from a string until no such pair remains, and return the final string. This is the standard adjacent-duplicate-pair formulation of the named problem. ### Clarifying Questions to Ask - Are exactly two matching neighbors removed at a time, rather than an entire longer run? - Can deleting a pair create another removable pair across the deletion boundary? ```hint Keep only the unresolved prefix The next character can create a removable pair only with the final surviving character so far. ``` ### What a Strong Answer Covers - Stack-based cancellation and cascading removals. - Odd-length runs versus even-length runs. - Linear total work despite repeated deletions. ### Follow-up Questions - How does removing every repeated run differ from removing pairs? - Can the input array itself serve as the stack?

Overview: Remove adjacent duplicate character pairs with a stack, handling cascading cancellations and distinguishing odd-length runs from whole-run deletion.

Read the full Whatnot Software Engineer interview experience this question came from

Whatnot logo
Whatnot
Feb 9, 2026
mediumSoftware EngineerTechnical ScreenCoding & Algorithms
1
0

Repeatedly remove a pair of equal adjacent characters from a string until no such pair remains, and return the final string. This is the standard adjacent-duplicate-pair formulation of the named problem.

Clarifying Questions to Ask Guidance

  • Are exactly two matching neighbors removed at a time, rather than an entire longer run?
  • Can deleting a pair create another removable pair across the deletion boundary?

What a Strong Answer Covers Guidance

  • Stack-based cancellation and cascading removals.
  • Odd-length runs versus even-length runs.
  • Linear total work despite repeated deletions.

Follow-up Questions Guidance

  • How does removing every repeated run differ from removing pairs?
  • Can the input array itself serve as the stack?