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

Remove Adjacent Duplicates in String II

Oracle logoOracle● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Oracle phone screen. A report names this well-known task. We chose the function signature, a fixed order for the output, and the input limits. Our version is about 98% the same as the reported question.

Given a lowercase string s and an integer k, repeatedly remove any group of exactly k adjacent equal characters. Concatenate the remaining parts after each removal.

Return the unique final string after no removable group remains.

Function

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

Examples

Example 1

s = "deeedbbcccbdaa"k = 3return = "aa"

Removing eee and ccc makes the three b characters adjacent. Removing them leaves aa.

Example 2

s = "pbbcggttciiippooaais"k = 2return = "ps"

Each adjacent pair is removed as it forms, including pairs created by earlier removals.

Example 3

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

No two adjacent characters are equal.

Constraints

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

Source note: Author-written prompt excerpt retained for source fidelity.

More Oracle Phone Screen questions

  • Remove Parentheses from a Plus-Minus ExpressionPHONE SCREEN · Seen Nov 2026
  • Trapping Rain WaterPHONE SCREEN · Seen Oct 2026
  • Shortest Window by Distinct-Value SumPHONE SCREEN · Seen Oct 2026
  • Detect a Cycle in a Directed GraphPHONE SCREEN · Seen Oct 2026
  • Time-Based Key-Value StorePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Sum Root-to-Leaf Binary NumbersPHONE SCREEN · Seen Oct 2026
  • Longest All-Present Attendance StreakPHONE SCREEN · Seen Oct 2026
  • Next PermutationPHONE SCREEN · Seen Sep 2026
  • Valid ParenthesesPHONE SCREEN · Seen Sep 2026
  • Valid Parenthesis StringPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • Most Frequent Call Path From Function Trace LogsRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
  • Adjacent Pair and Run RemovalWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot 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

Oracle interview experiences

  • Oracle SWE Onsite Interview Experience: 1 Experience
All Oracle interview questionsSee Oracle hiring insights
Saved
class Solution {
    public String removeDuplicates(String s, int k) {
      // Write your code here.
    }
}
Checking account…