Remove Adjacent Duplicates in String II
Updated
Problem statement
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) → StringExamples
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.scontains 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