Back to course home
0% completed
Minimum Add to Make Parentheses Valid (medium)
Problem Statement
Given a string str containing '(' and ')' characters, find the minimum number of parentheses that need to be added to a string of parentheses to make it valid.
A valid string of parentheses is one where each opening parenthesis '(' has a corresponding closing parenthesis ')' and vice versa. The goal is to determine the least amount of additions needed to achieve this balance.
Examples
- Example 1:
- Input: "(()"
- Expected Output: 1
- Justification: The string has two opening parentheses and one closing parenthesis
.....
.....
.....
Like the course? Get enrolled and start learning!