Skip to main content

Parenthesis Problems

Below is a list of common parenthesis-related problems.

  1. Valid Parentheses
    LeetCode: Valid Parentheses

    • Problem: Given a string containing just the characters (, ), {, }, [ and ], determine if the input string is valid.
    • Keywords: Stack, Matching Parentheses.
  2. Generate Parentheses
    LeetCode: Generate Parentheses

    • Problem: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
    • Keywords: Backtracking, Recursion.
  3. Longest Valid Parentheses
    LeetCode: Longest Valid Parentheses

    • Problem: Find the length of the longest valid (well-formed) parentheses substring.
    • Keywords: Dynamic Programming, Stack.
  4. Remove Invalid Parentheses
    LeetCode: Remove Invalid Parentheses

    • Problem: Remove the minimum number of invalid parentheses to make the input string valid.
    • Keywords: BFS, DFS, Backtracking.
  5. Check if Parentheses are Balanced
    GeeksForGeeks: Check for Balanced Parentheses

    • Problem: Given an expression string, write a program to check if the string contains balanced parentheses.
    • Keywords: Stack.
  6. Minimum Add to Make Parentheses Valid
    LeetCode: Minimum Add to Make Parentheses Valid

    • Problem: Return the minimum number of parentheses you must add to make the parentheses string valid.
    • Keywords: Stack, Greedy.
  7. Valid Parenthesis String
    LeetCode: Valid Parenthesis String

    • Problem: Given a string containing (, ), and *, determine if it is valid.
    • Keywords: Greedy, Stack, Two Pointers.
  8. Score of Parentheses
    LeetCode: Score of Parentheses

    • Problem: Given a balanced parentheses string S, compute the score of the string based on rules.
    • Keywords: Stack, Recursion.
  9. Remove Outermost Parentheses
    LeetCode: Remove Outermost Parentheses

    • Problem: A valid parentheses string is either () or can be written as A + B, where A and B are valid strings. Remove the outermost parentheses of every primitive string.
    • Keywords: String, Stack.

Additional Parenthesis Problems

  1. Minimum Number of Swaps to Make the String Balanced
    LeetCode: Minimum Number of Swaps to Make the String Balanced

    • Problem: You are given a string s of even length consisting of parentheses only. You can swap two adjacent characters. Return the minimum number of swaps to make the string balanced.
    • Keywords: Greedy, Two Pointers, Stack.
  2. Different Ways to Add Parentheses
    LeetCode: Different Ways to Add Parentheses

    • Problem: Given a string expression of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators using parentheses.
    • Keywords: Divide and Conquer, Recursion.
  3. Minimum Remove to Make Valid Parentheses
    LeetCode: Minimum Remove to Make Valid Parentheses

    • Problem: Given a string s of '(', ')', and lowercase English characters, remove the minimum number of invalid parentheses to make the string valid.
    • Keywords: Stack, String.
  4. Check if a Parentheses String Can Be Valid
    LeetCode: Check if a Parentheses String Can Be Valid

    • Problem: Given a string s containing only parentheses and the string locked, check if the parentheses string s can be valid after some swaps of adjacent parentheses.
    • Keywords: Greedy, Stack.