FastPrepRemove All Adjacent Duplicates in String II
Problems/Remove All Adjacent Duplicates in String II

Remove All Adjacent Duplicates in String II

The Walt Disney Company logoThe Walt Disney Company● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The original report names the phone-screen task phonetically as 1-2-0-9. The official task identity is Remove All Adjacent Duplicates in String II. The report does not provide the statement, bounds or examples. This practice follows that named equal-run deletion task with authored bounds, lowercase strings and empty input support. About 85% of the reported task scope is represented, as an editorial estimate rather than original-code similarity.

Given a lowercase string s and an integer k, repeatedly remove a block of exactly k adjacent equal letters. The parts on either side join after each removal and may create another removable block.

Return the final string when no removal is possible. The result is unique. For this exercise, an empty input or a completely removed string returns the empty string.

Function

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

Examples

Example 1

s = "abbbaa"k = 3return = 

Removing bbb joins the surrounding letters into aaa. Removing aaa then leaves the empty string.

Example 2

s = "aabcccbd"k = 3return = aabbd

Removing ccc leaves aabbd. Every remaining run has length below three, so aabbd is final.

Constraints

  • 0 <= s.length <= 4000
  • 2 <= k <= 100
  • s contains only lowercase English letters.

More The Walt Disney Company problems

  • Find All Paths for a Name in a File SystemPHONE SCREEN · Seen Nov 2026
  • Resizable Array-Backed Integer SetPHONE SCREEN · Seen Sep 2026
  • Shortest Path with Directional Move CostsPHONE SCREEN · Seen Sep 2026
All The Walt Disney Company interview questionsSee The Walt Disney Company hiring insights
Saved
class Solution {
    public String removeDuplicates(String s, int k) {
        // Write your code here
    }
}

Enter a value

Checking account…