Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Generate Parentheses
Brute Force
Backtracking
Divide & Conquer
Small
Standard
Minimal
Custom
n
=
2
candidate string
(enumerating…)
generate all strings, keep the balanced ones
result
0
(none yet)
candidate string
(enumerating…)
generate all strings, keep the balanced ones
result
0
(none yet)
candidate + running balance
(
1
(
2
(
3
(
4
ends unbalanced — discard
result
0
(none yet)
candidate + running balance
(
1
(
2
)
1
(
2
ends unbalanced — discard
result
0
(none yet)
candidate + running balance
(
1
)
0
(
1
(
2
ends unbalanced — discard
result
1
(())
candidate + running balance
(
1
)
0
)
-1
(
0
")" at index 2 closes with nothing open
result
2
(())
()()
candidate + running balance
)
-1
(
0
(
1
(
2
")" at index 0 closes with nothing open
result
2
(())
()()
candidate + running balance
)
-1
(
0
)
-1
(
0
")" at index 0 closes with nothing open
result
2
(())
()()
candidate + running balance
)
-1
)
-2
(
-1
(
0
")" at index 0 closes with nothing open
result
2
(())
()()
candidate + running balance
)
-1
)
-2
)
-3
(
-2
")" at index 0 closes with nothing open
result
2
(())
()()
candidate string
(enumerating…)
2 valid combinations
result
2
(())
()()
Step:
Generate all 2^4 strings of length 4, keep the balanced ones.
0 / 18
Small
Standard
Minimal
Custom
n
=
2
0 / 18
Step:
Generate all 2^4 strings of length 4, keep the balanced ones.