Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Remove Invalid Parentheses
BFS
Backtracking
Iterative
Valid
One Extra Close
With Letter
One Extra Open
Custom
s
=
()
input "()"
level 0 · 0 removals · 0 strings
result
0
(searching…)
remove one char per level; stop at first valid level
input "()"
level 0 · 0 removals · 0 strings
result
0
(searching…)
remove one char per level; stop at first valid level
input "()"
level 0 · 0 removals · 1 string
()
result
0
(searching…)
checking level 0, string 1/1
input "()"
level 0 · 0 removals · 1 string
()
result
1
()
level 0: found 1 valid — stop
input "()"
level 0 · 0 removals · 0 strings
result
1
()
1 result · 0 removals
Step:
Each removal is one BFS level; stop at the first level with a valid string.
0 / 3
Valid
One Extra Close
With Letter
One Extra Open
Custom
s
=
()
0 / 3
Step:
Each removal is one BFS level; stop at the first level with a valid string.