FastPrepBalanced Parentheses with Sequential Left Deletions
Problems/Balanced Parentheses with Sequential Left Deletions

Balanced Parentheses with Sequential Left Deletions

Google logoGoogle● HardFULLTIMEINTERNPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: Inferred as a Google L3 phone-screen question from the interview account's coding-round framing and interactive clarification cues; the source does not directly name the stage. It also leaves exact-versus-at-most deletion semantics, the callable result, empty-result behavior, and bounds open; this practice version applies each digit independently as exactly that many deletions from currently retained left parentheses, returns a boolean with the empty result balanced, and limits input length to 16. Problem match confidence: approximately 72%.

Special thanks: 🌷 A special thank you to a lovely, amazing fren for sharing that this question appeared in an internship interview on September 25, 2026! (∩˃o˂∩)♡ 💜

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.

More Google problems

  • Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
  • Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public boolean canMakeBalanced(String s) {
        // write your code here
    }
}
Checking account…