Skip to content

Practice Valid Parenthesis String

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#678
LeetCode Problem

Valid Parenthesis String

Problem Statement

Determine whether s can form a balanced parentheses string. It contains only (, ) and *. Each * may independently stand for one opening parenthesis, one closing parenthesis or an empty string. Every closing parenthesis must match an earlier opening parenthesis, and no unmatched parenthesis may remain. Return whether some choices for the stars satisfy these rules.

Source: Valid Parenthesis String on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "()"
Output
true

# Example 2

Input
s = "(*)"
Output
true

# Example 3

Input
s = "(*))"
Output
true

Constraints

1 <= s.length <= 100
s[i] is '(', ')' or '*'.

Related LeetCode Problems

Practice more problems similar to Valid Parenthesis String.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.