Parenthesis Problems
Below is a list of common parenthesis-related problems.
-
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.
- Problem: Given a string containing just the characters
-
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.
- Problem: Given
-
Longest Valid Parentheses
LeetCode: Longest Valid Parentheses- Problem: Find the length of the longest valid (well-formed) parentheses substring.
- Keywords: Dynamic Programming, Stack.
-
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.
-
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.
-
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.
-
Valid Parenthesis String
LeetCode: Valid Parenthesis String- Problem: Given a string containing
(
,)
, and*
, determine if it is valid. - Keywords: Greedy, Stack, Two Pointers.
- Problem: Given a string containing
-
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.
- Problem: Given a balanced parentheses string
-
Remove Outermost Parentheses
LeetCode: Remove Outermost Parentheses- Problem: A valid parentheses string is either
()
or can be written asA + B
, whereA
andB
are valid strings. Remove the outermost parentheses of every primitive string. - Keywords: String, Stack.
- Problem: A valid parentheses string is either
Additional Parenthesis Problems
-
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.
- Problem: You are given a string
-
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.
-
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.
- Problem: Given a string
-
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 stringlocked
, check if the parentheses strings
can be valid after some swaps of adjacent parentheses. - Keywords: Greedy, Stack.
- Problem: Given a string