Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Longest Turbulent Subarray
Bookmark
Brute Force
Dynamic Programming
Input
Classic
Full Zigzag
Monotone
All Equal
Custom
arr
=
[9, 4, 2, 10, 7, 8, 8, 1, 9]
0
1
2
3
4
5
6
7
8
9
4
2
10
7
8
8
1
9
0
1
2
3
4
5
6
7
8
9
4
2
10
7
8
8
1
9
run =
2
best =
2
▼
0
1
2
3
4
5
6
7
8
9
4
2
10
7
8
8
1
9
j
i
same direction, not alternating
→ stop at [0..1]
run =
4
best =
4
▼
0
1
2
3
4
5
6
7
8
9
4
2
10
7
8
8
1
9
j
i
run [1..4] length
4
new best
run =
5
best =
5
=
0
1
2
3
4
5
6
7
8
9
4
2
10
7
8
8
1
9
j
i
equal breaks the run
→ stop at [1..5]
run =
3
best =
5
▼
0
1
2
3
4
5
6
7
8
9
4
2
10
7
8
8
1
9
j
i
run [2..4] length
3
≤ best 5
run =
2
best =
5
▼
0
1
2
3
4
5
6
7
8
9
4
2
10
7
8
8
1
9
j
i
run [3..4] length
2
≤ best 5
run =
3
best =
5
=
0
1
2
3
4
5
6
7
8
9
4
2
10
7
8
8
1
9
j
i
equal breaks the run
→ stop at [3..5]
run =
2
best =
5
=
0
1
2
3
4
5
6
7
8
9
4
2
10
7
8
8
1
9
j
i
equal breaks the run
→ stop at [4..5]
run =
3
best =
5
▲
0
1
2
3
4
5
6
7
8
9
4
2
10
7
8
8
1
9
j
i
run [6..8] length
3
≤ best 5
run =
-
best =
5
0
1
2
3
4
5
6
7
8
9
4
2
10
7
8
8
1
9
Longest turbulent length =
5
algo
master
.
io
Step:
A turbulent run strictly alternates rising and falling. From each start, extend while it keeps alternating.
0 / 21
Input
Classic
Full Zigzag
Monotone
All Equal
Custom
arr
=
[9, 4, 2, 10, 7, 8, 8, 1, 9]
0 / 21
algo
master
.
io
Step:
A turbulent run strictly alternates rising and falling. From each start, extend while it keeps alternating.