Free written solution

Minimum Insertions to Balance a Parentheses String (LeetCode 1541): Solution and Explanation

Each '(' must be closed by two adjacent ')'. Count the fewest characters to insert so the whole string is balanced. For (())) the answer is 1, for ))())( it is 3.

Read the intuition, approach, code and complexity →