Coding

Calculate the minimum number of parentheses to add to make a string valid.

A parentheses string is valid if and only if it is empty, or properly balanced. Return the minimum number of parentheses you must add to make the resulting string valid.

Input: s = "((("

Output: 3

Explanation: There are three open parentheses without any matching closing parentheses, so 3 closing parentheses must be added.

Was asked at

Practice this question with AI

First session is free - no credit card required.

Go Premium

More interviews, more skills, more success.

No answers yet

Be the first to share your approach to this question

Practice More Questions