LC 678 — Problem

Given a string s containing only three types of characters: (, ), and *, return true if s is valid. A * can be treated as a single (, a single ), or an empty string.

Input: s = “(*)”
Output: true
Input: s = “(*))”
Output: true
Explanation: Assign * as "(“ to get ”(())".

Constraints: 1 ≤ s.length ≤ 100 · s[i] is '(', ')' or '*'

Given a string containing (, ), and *, determine if it can be valid. Each * can be treated as (, ), or an empty string. The question seems simple: just try each possibility and check. But how many possibilities are there?

Each star can stand for (, ), or empty string. How bad does the brute force get? Try a few assignments below and find out.

FIG. 1 — INPUT STRING

What should the star become? Try all three options.