Baseline Greedy Approach · Easy O(n) · O(1)
A reconciliation script parses ledger lines containing opens, closes, and wildcard tokens that may act as either — or vanish entirely. A line is acceptable if some assignment of the wildcards makes the brackets balance in order. The auditor tracks the lowest and highest plausible open-count while scanning, and accepts the line only if zero opens remains reachable at the end.
Input: A string s containing only '(', ')' and '*'.
Output: Return true if s can be a valid parenthesis sequence under some wildcard assignment.
1 <= s.length <= 100s[i] is '(', ')' or '*'Input: {"s":"(*))"}
Output: true
The wildcard plays the opener, matching the two closers that follow.
Input: {"s":"(*)"}
Output: true
Here the wildcard acts as the closer.