FastPrepValid Parenthesis String

Valid Parenthesis String

Oracle logoOracle● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

Given a string s containing '(', ')', and '*', return whether it can become a valid parenthesis string.

Each '*' may independently represent an opening parenthesis, a closing parenthesis, or the empty string.

Function

checkValidString(s: String) → boolean

Examples

Example 1

s = "(*)"return = true

The wildcard may be empty.

Example 2

s = "(*))"return = true

Treat the wildcard as an opening parenthesis.

Constraints

  • 0 <= s.length <= 10^5.
  • s contains only (, ), and *.

More Oracle problems

See Oracle hiring insights
public boolean checkValidString(String s) {
  // write your code here
}
s"(*)"
expectedtrue
Checking account…