Skip to content
BASA DSA

Valid Parenthesis String

MediumGreedy

A star in s may represent an opening parenthesis, a closing parenthesis or an empty string. Return whether some choices make the complete string balanced.

Example 1

Input
s = "(*))"
Output
true

Explanation

Use the star as an opener to obtain (()).

Example 2

Input
s = ")*("
Output
false

Explanation

The initial closer has nothing before it to balance it.

Example 3

Input
s = "***"
Output
true

Explanation

Use all stars as empty strings to obtain a balanced sequence.

Constraints

  • 1 <= len(s) <= 100
  • Characters are (, ), *

Function contractcheckValidStringArguments: json
Loading draft…
SolutionRuns on your device
Loading draft…