Practice Longest Turbulent Subarray
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Return the maximum length of a contiguous subarray whose adjacent comparisons strictly alternate between less-than and greater-than. Either comparison may come first; equal neighbors break the alternating run. A single element is a valid length-one run.
Source: Longest Turbulent Subarray on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
arr = [9,4,2,10,7,8,8,1,9]
Output
5
# Example 2
Input
arr = [4,8,12,16]
Output
2
# Example 3
Input
arr = [100]
Output
1
Constraints
1 <= arr.length <= 4 * 10^4
0 <= arr[i] <= 10^9
Related LeetCode Problems
Practice more problems similar to Longest Turbulent Subarray.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.