mediumGreedyFacebookMicrosoft
Bracket Elasticity Check
A parser verifies that a mix of '(' , ')' and wildcard '*' (which can be '(' , ')' or empty) is a valid bracket string.
Given a string of '(', ')', '*', return true iff some choice for each '*' makes the brackets balanced.
Choose approach
(
0i
*
1)
2)
3Maprange
lo→1
hi→1
1/5
Narrationstep 1 of 5
i=0 ('('): lo=1, hi=1.
Variables
i=0
lo=1
hi=1
How to think about it
- Clip lo at 0 (never negative).
- hi<0 means ')' exceeded any possibility.
Edge cases to catch in interview
- Empty string -> true.
- All stars -> true.
Examples
Example 1
true{"s":"(*)","values":["(","*",")"]}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed