FastPrepRemove K Adjacent Duplicates
Problems/Remove K Adjacent Duplicates

Remove K Adjacent Duplicates

WhatNot logoWhatNot● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: An engineer who was changing jobs had this at Whatnot between April and June 2026, in a technical phone screen that covered both system design and coding. It was the follow-up to the first coding task, which deletes pairs of equal adjacent letters (that task is also on this site). The poster says it was a standard problem asked without changes, and did not pass the screen.

Only the name of the task was given, so the limits here are the usual ones: lowercase letters, up to 10^5 characters and k from 2 to 10^4.

Our version is about 90% the same as the reported question.

You are given a string s of lowercase English letters and an integer k.

One removal picks k adjacent characters of s that are all the same letter and deletes them. The parts to the left and right of them are joined, so letters that were apart can become neighbors.

Keep making removals until no k equal letters stand next to each other, and return the string that is left. The final string is the same no matter which removal you make first, so the answer is unique. It can be empty.

Function

removeDuplicates(s: String, k: int) → String

Examples

Example 1

s = "baaabbc"k = 3return = "c"

Remove "aaa" to get "bbbc". Now three bs stand next to each other, so remove them as well. Only "c" is left.

Example 2

s = "aaaaa"k = 2return = "a"

Each removal takes exactly two of the as: "aaaaa" becomes "aaa", then "a". One a cannot be removed on its own.

Example 3

s = "abcd"k = 2return = "abcd"

No two neighbors are equal, so nothing is removed.

Example 4

s = "abbbaa"k = 3return = ""

Removing "bbb" brings the first a next to the last two, which gives "aaa". Removing that leaves the empty string.

Constraints

  • 1 <= s.length <= 105
  • 2 <= k <= 104
  • s contains only lowercase English letters.

More WhatNot Phone Screen questions

  • Merge Sorted Squares of Two ArraysPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Adjacent Pair and Run RemovalPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • User Journey PathsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • User Journey Paths from a Log StreamPHONE SCREEN · Seen Nov 2026
  • Reachable Exits in an Obstacle GridPHONE SCREEN · Seen Oct 2026
  • Palindrome with One DeletionPHONE SCREEN · Seen Oct 2026
  • Search a 2D MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Attraction Route Without Reusing TrailsPHONE SCREEN · Seen Sep 2026
  • Earliest Car for Each PassengerPHONE SCREEN · Seen Sep 2026
  • Minimum Stores for a Shopping ListPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • Most Frequent Call Path From Function Trace LogsRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
  • Remove Parentheses from a Plus-Minus ExpressionOracle · PHONE SCREENOracle interview questions
  • Parse a Partial JSON StreamListen Labs · PHONE SCREEN
  • Decode StringCompass International Holdings · PHONE SCREENCompass International Holdings interview questions
  • Remove K DigitsProcol · PHONE SCREEN
  • Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Inverse-Depth Nested List SumLinkedIn · PHONE SCREENLinkedIn interview questions
  • Multiline Text Editor with Cursor MovementDatologyAI · PHONE SCREEN
  • Run a Stack Language InterpreterJane Street · PHONE SCREENJane Street interview questions
  • Trace Nested Object Destruction OrderArista Networks · PHONE SCREENArista Networks interview questions

Interview reports that mention this question

  • Whatnot interviews · May 2026

WhatNot interview experiences

  • Whatnot OA · 2024
  • Whatnot OA · November 2023
  • Whatnot interviews · November 2023
  • Whatnot interviews · February 2024
  • Whatnot interviews · March 2024
All WhatNot interview questionsSee WhatNot hiring insights
Saved
class Solution {
    public String removeDuplicates(String s, int k) {
        // write your code here
    }
}
Checking account…