Problem
A subarray is turbulent if the comparison sign flips between each adjacent pair: up, down, up, ... or down, up, down, ... (for example a < b > c < d). Equal neighbours break it. Given arr, return the length of the longest turbulent subarray. A single element counts as turbulent.
Example 1
- Input
- arr = [9, 4, 2, 10, 7, 8, 8, 1, 9]
- Output
- 5
- Why
- [4, 2, 10, 7, 8]
Example 2
- Input
- arr = [4, 8, 12, 16]
- Output
- 2
Example 3
- Input
- arr = [100]
- Output
- 1
Constraints
1 <= arr.length <= 4 * 10^40 <= arr[i] <= 10^9