FastPrepMinimum Removal for Balanced Parentheses
Problems/Minimum Removal for Balanced Parentheses

Minimum Removal for Balanced Parentheses

Meta logoMeta● MediumNEW GRADPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Meta new grad phone screen. The original report gives a string of letters, digits and parentheses, asks for the fewest deletions, and does not allow adding characters. It does not say which of several equally small answers to pick, or give an input limit. Here, we remove unmatched parentheses in a fixed order and added a usual limit.

Given a string s containing ASCII letters, digits, opening parentheses, and closing parentheses, remove the minimum possible number of parentheses so that the remaining parentheses are balanced. You may not add or reorder characters.

Use this rule when several minimum-removal results are possible:

  1. Scan from left to right. Discard every closing parenthesis that has no unmatched opening parenthesis before it.
  2. After that scan, discard the still-unmatched opening parentheses from right to left.

Return the retained characters in their original relative order. Letters and digits are always retained.

Function

makeParenthesesBalanced(s: String) → String

Examples

Example 1

s = "lee(t(c)o)de)"return = "lee(t(c)o)de"

The final closing parenthesis has no matching opening parenthesis, so removing it produces a balanced result with one deletion.

Example 2

s = "a)b(c)d"return = "ab(c)d"

The closing parenthesis after a is unmatched during the left-to-right scan. Every other parenthesis can be retained.

Example 3

s = "))(("return = ""

Both closing parentheses are unmatched, and both opening parentheses remain unmatched, so all four are removed.

Constraints

  • 1 <= s.length <= 100000.
  • s contains only ASCII letters, digits, (, and ).

More Meta Phone Screen questions

  • Fuzzy Word Lookup With One Misspelled LetterPHONE SCREEN · Seen Nov 2026
  • Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Run-Length Encoded Vector Dot ProductPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Best Time to Buy and Sell StockPHONE SCREEN · Seen Nov 2026
  • First Element Greater Than KPHONE SCREEN · Seen Nov 2026
  • Count Events in Rolling Minute WindowsPHONE SCREEN · Seen Oct 2026
  • Valid Word AbbreviationPHONE SCREEN · Seen Oct 2026
  • Shortest Path in a Binary MatrixPHONE SCREEN · Seen Sep 2026
  • Deterministic K-Means AssignmentsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • Remove K DigitsProcol · PHONE SCREEN
  • Remove K DigitsThe D.E. Shaw Group · ONSITE INTERVIEWThe D.E. Shaw Group interview questions
  • Remove K DigitsAmazon · ONSITE INTERVIEW
  • Largest K-Digit SubsequenceGoogle · ONSITE INTERVIEWGoogle interview questions
  • Minimum Remove to Make Valid ParenthesesBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Remove K DigitsMorgan Stanley · ONSITE INTERVIEWMorgan Stanley interview questions
  • Smallest Number After Removing k DigitsAdobe · PHONE SCREENAdobe interview questions
  • Lexicographically Largest Distinct-Letter SubsequenceNavan · PHONE SCREENNavan interview questions
  • Substring RemovalJP Morgan Chase · OAJP Morgan Chase interview questions
  • Modify the StringYahoo · OAYahoo interview questions

Meta interview experiences

  • Meta PhD SWE Intern AI Coding Phone Screen: 1 Experience
  • Meta Business Support Engineer Phone Screen: 1 Experience
  • Meta Software Engineer Onsite Questions: 3 Experiences
  • Meta AI Native Engineer OA and Onsite: 1 Experience
  • Meta AI-Native Coding Interview: 3 Experiences
  • Meta Production Engineer Intern Questions: 6 Experiences
All Meta interview questionsSee Meta hiring insights
Saved
class Solution {
    public String makeParenthesesBalanced(String s) {
        // Write your code here.
    }
}
Checking account…