Repeated Adjacent Pair Deletion
Updated
Problem statement
Given a string s, repeatedly remove adjacent pairs of equal characters. After a removal, newly adjacent equal characters must also be removed.
Return the unique remaining string, with no adjacent equal pair left to remove. The process is equivalent to applying removals from left to right with a stack.
Function
removeAdjacentPairs(s: String) → StringExamples
Example 1
s = "ACCAB"return = "B"Remove CC to get AAB, then remove AA to get B.
Example 2
s = "abbaca"return = "ca"Removing bb creates aa, whose removal leaves ca.
Example 3
s = "abc"return = "abc"No adjacent pair is equal.
Constraints
0 <= s.length <= 200000.scontains ASCII letters.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Valid ParenthesesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Valid ParenthesesEPAM · ONSITE INTERVIEWEPAM interview questions
- Valid ParenthesesQualys · ONSITE INTERVIEWQualys interview questions
- Rich Text Parser Part 1 (Validate Tokens)Figma · PHONE SCREEN · ONSITE INTERVIEWFigma interview questions
- Valid ParenthesesAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Valid ParenthesesKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
- Valid ParenthesesSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Minimum Parenthesis Removals and Their IndicesDoorDash · ONSITE INTERVIEWDoorDash interview questions
- Valid ParenthesesBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Maximum Parenthesis Nesting DepthRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions