Remove minimum parentheses to balance string

Quick Overview

This question evaluates string-processing and algorithm-design skills within the Coding & Algorithms domain, focusing on balancing parentheses, correctness proofs for minimal edits, and time/space complexity analysis.

Remove minimum parentheses to balance string

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Given a string s containing lowercase letters and the characters '(' and ')', remove the minimum number of parentheses so that the resulting string is valid (balanced and properly ordered). Return any one valid result while preserving the relative order of the remaining characters. Target O(n) time and O(n) or O( 1) extra space. Describe the algorithm, argue minimality, and analyze complexity. As a follow-up, discuss how to output all possible valid results if multiple exist.

Quick Answer: This question evaluates string-processing and algorithm-design skills within the Coding & Algorithms domain, focusing on balancing parentheses, correctness proofs for minimal edits, and time/space complexity analysis.

|Home/Coding & Algorithms/Meta
Meta logo
Meta
Sep 6, 2025, 12:00 AM
mediumSoftware EngineerTechnical ScreenCoding & Algorithms
2
0

Given a string s containing lowercase letters and the characters '(' and ')', remove the minimum number of parentheses so that the resulting string is valid (balanced and properly ordered). Return any one valid result while preserving the relative order of the remaining characters. Target O(n) time and O(n) or O(

  1. extra space. Describe the algorithm, argue minimality, and analyze complexity. As a follow-up, discuss how to output all possible valid results if multiple exist.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...