Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Longest Valid Parentheses
Bookmark
Brute Force
DP
Stack
Two-Pass
Input
Example 1
Example 2
Example 3
Custom
s
=
(()
count =
0
maxLen =
0
(
0
(
1
)
2
count =
0
maxLen =
0
(
0
(
1
)
2
count =
0
maxLen =
0
(
0
(
1
)
2
count =
0
maxLen =
0
(
0
(
1
)
2
j
i
new window from i =
0
count =
2
maxLen =
0
(
0
(
1
)
2
j
i
'('
→ balance =
2
count =
2
maxLen =
0
(
0
(
1
)
2
j
i
count =
0
maxLen =
0
(
0
(
1
)
2
j
i
new window from i =
1
count =
1
maxLen =
0
(
0
(
1
)
2
j
i
'('
→ balance =
1
count =
0
maxLen =
0
(
0
(
1
)
2
j
i
count =
0
maxLen =
2
(
0
(
1
)
2
j
i
valid!
length =
2
(
0
(
1
)
2
maxLen =
2
algo
master
.
io
Step:
Brute force: hand every even-length window to isValid, keep the longest that passes.
0 / 11
Input
Example 1
Example 2
Example 3
Custom
s
=
(()
0 / 11
algo
master
.
io
Step:
Brute force: hand every even-length window to isValid, keep the longest that passes.