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.

Community Answers

1 answer from the community

Expert Answer

Unlock Full Access

Answer any un-answered question from our database to unlock all community answers for 30 days.

Give & Take

Practice More Questions

1 answer published. Last candidate submission on Oct 25 2026, 5:45am PDT. Interview question asked to Software Engineers interviewing at Renew Power, Delhivery, NoBroker and other companies. Original question asked: Calculate the minimum number of parentheses to add to make a string valid.. Question last reported by a candidate interviewing at Clubhouse for a Software Engineer interview on Nov 7 2026, 1:46am PDT.