Balanced Parentheses with Sequential Left Deletions
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Google's September 2026 OA has a parentheses problem that looks friendly and isn't. The input caps at 16 characters, which is the loudest hint in the statement. It means exponential search is expected, so don't hunt for a clever greedy that doesn't exist. Each digit forces you to delete exactly d retained parentheses to its left, and you choose which ones. That choice is the whole problem. If you blank on how to structure the search, StealthCoder runs invisibly during the live OA and gives you a working solution as a safety net. Here's the shape of it.
The problem
You are given a string s containing parentheses and decimal digits. Process its characters from left to right. A parenthesis is retained. When a digit d is reached, remove the digit and delete exactly d of the currently retained parentheses to its left, choosing any such positions. Return true if some sequence of choices leaves a balanced parenthesis string after every character has been processed. Each digit is applied separately; digits are never combined. If fewer than d parentheses are currently retained, that choice is impossible. The empty string is balanced. Function canMakeBalanced(s: String) → boolean Examples Example 1 s = "(()1" return = true Deleting either one of the first two opening parentheses leaves (). Example 2 s = "((1))" return = false After deleting one opening parenthesis, two closing parentheses remain. Example 3 s = "()0" return = true The digit zero removes nothing, leaving (). Constraints 1 ≤ s.length ≤ 16. Every character of s is (, ), or a digit from 0 through 9. Each digit deletes exactly its own value from the retained parentheses to its left.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The constraint of 16 characters rules out nothing exponential, so brute force with memoization is the intended route. Model the retained parentheses as a list. When you hit a digit d, try every subset of size d from the current list, remove it, and recurse. At the end, check balance with a simple counter. Two things keep it fast. First, memoize on (index, retained string), since many deletion choices produce the same string. Second, prune early: if fewer than d parentheses remain, that branch dies. The common pitfall is deleting from only the nearest d parentheses, or treating the digit as a number like 12. Digits are applied separately. Example 2 trips people up because deleting one opening paren leaves two closers. StealthCoder is your hedge if the subset enumeration or the memo key goes sideways under live pressure.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Balanced Parentheses with Sequential Left Deletions cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Google's OA.
Google reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Balanced Parentheses with Sequential Left Deletions FAQ
What's the trick in this Google OA problem?+
Read the 16-character limit as permission to search. Track the retained parentheses as a string, and at each digit try every way to delete exactly d of them. Memoize on index plus the current string so duplicate states collapse. Check balance only at the end.
How hard is this really?+
Medium on difficulty, but the statement is confusing. The hard part is realizing you choose which parentheses to delete, not just how many. Once you commit to subset enumeration with memoization, the code is short. Most people lose time hunting for a greedy.
Can a greedy approach work here?+
Not safely. Deleting the leftmost or rightmost parentheses can fail on cases like Example 1 versus Example 2, where which paren you remove changes balance. With 16 characters, an exhaustive search is cheap enough that you shouldn't risk a wrong greedy.
What edge cases should I test?+
Test a digit zero (removes nothing), a digit larger than the retained count (that choice is impossible), an empty result (balanced), and a string with no digits at all. Also test digits at the very start, where nothing is retained yet.
How do I prepare for this in 48 hours?+
Practice backtracking with memoization on small strings, especially generating combinations of a given size from a list. Write a balance checker from memory. Then dry-run the three examples by hand. That covers nearly everything this problem needs.