DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
medium
String

Minimum Remove to Make Valid Parentheses

**Problem Statement:** Given the required input arguments, write an efficient algorithm to solve the **Minimum Remove to Make Valid Parentheses** problem. Implement the required logic as specified by standard definitions for this classic algorithmic challenge. **Hint / Expected Approach:** Stack for indices; collect invalid + rebuild **Edge Cases to Consider:** - (1) No parentheses - (2) All balanced - (3) Nested unmatched

Examples

Example 1
Input: "lee(t(c)o)de)"
Output: "lee(t(c)o)de"
Explanation: Remove last `)`
Example 2
Input: "a)b(c)d"
Output: "ab(c)d"
Explanation: Remove first `)`
Example 3
Input: "))(("
Output: ""
Explanation: Remove all

Constraints

  • ▪1 <= s.length <= 10^4
  • ▪s consists of printable ASCII characters
  • ▪Solve with optimal space complexity

Watch Out For Edge Cases

  • ▪No parentheses
  • ▪All balanced
  • ▪Nested unmatched
Frequently Asked At
MetaAmazonMicrosoftAdobe