Harpreet's Newsletter

Harpreet's Newsletter

Minimum Add to Make Parentheses Valid

Google Interview Question

Harpreet Singh's avatar
Harpreet Singh
Nov 03, 2025
∙ Paid

Problem Overview

Difficulty: Medium
LeetCode Pattern: Stack

You are given a string s containing only ( and ). In one move, you can insert a parenthesis anywhere. Return the minimum number of insertions needed to make s valid.

Note: A string of parentheses is valid if:

  • It is empty.

  • Or it can be formed by:

    • concatenating two valid strings.

  • Or it is wrapped like:

    • (A…

Keep reading with a 7-day free trial

Subscribe to Harpreet's Newsletter to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Harpreet Singh · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture