FastPrepAdjacent Pair and Run Removal
Problems/Adjacent Pair and Run Removal

Adjacent Pair and Run Removal

WhatNot logoWhatNot● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names an adjacent-duplicate exercise phonetically and a similar follow-up without k. Pair cancellation is the selected baseline; simultaneous removal of complete repeated runs, input bounds, and the two-result practice interface are authored clarifications. Approximate source match: 75%.

Given a string s, compute two independent results, each starting from the original string.

  1. Pair removal: repeatedly remove the leftmost pair of equal adjacent characters until no equal adjacent pair remains. Remove exactly two characters each time.
  2. Whole-run removal: in one round, identify every maximal contiguous run of equal characters whose length is at least two, and remove all such runs simultaneously. Newly adjacent characters are considered only in the next round. Repeat until a round removes nothing.

Return a two-element string array [pairResult, runResult] in that order. A maximal run includes every consecutive occurrence of the same character at that location. Characters separated by a different surviving character are not duplicates to remove.

The source reports an adjacent-duplicate task followed by a version without a supplied k. For this practice exercise, the follow-up uses the explicit simultaneous whole-run rule above; its round timing was not specified in the report.

Function

removeAdjacentVariants(s: String) → String[]

Examples

Example 1

s = "abbbaa"return = ["ab","a"]

Pairs: abbbaa → abaa → ab. Runs: remove bbb and the final aa together, leaving a.

Example 2

s = "abccba"return = ["",""]

Pairs cancel cc, then bb, then aa. Runs remove cc in round 1, bb in round 2, and aa in round 3; both results are empty.

Example 3

s = "abcab"return = ["abcab","abcab"]

No equal adjacent characters exist, so both results remain abcab.

Constraints

  • 0 <= s.length <= 2000.
  • s contains only lowercase English letters.
  • Both results start independently from the original s; an empty input returns two empty strings.

More WhatNot problems

  • User Journey PathsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Palindrome with One DeletionPHONE SCREEN · Seen Oct 2026
  • Attraction Route Without Reusing TrailsPHONE SCREEN · Seen Sep 2026
All WhatNot interview questionsSee WhatNot hiring insights
Saved
class Solution {
    public String[] removeAdjacentVariants(String s) {
        // write your code here
    }
}
Checking account…