Given an integer array arr, return the maximum length of a turbulent subarray of arr.
A subarray is considered turbulent if the comparison sign alternates between each consecutive pair of elements throughout the subarray.
Formally, a subarray arr[i...j] is turbulent if for every index
• arr[k] > arr[k + 1] for odd arr[k] < arr[k + 1] for even
• arr[k] < arr[k + 1] for odd arr[k] > arr[k + 1] for even
Constraints:
arr.length
arr[i]
Given an integer array arr, return the maximum length of a turbulent subarray of arr.
A subarray is considered turbulent if the comparison sign alternates between each consecutive pair of elements throughout the subarray.
Formally, a subarray arr[i...j] is turbulent if for every index
• arr[k] > arr[k + 1] for odd arr[k] < arr[k + 1] for even
• arr[k] < arr[k + 1] for odd arr[k] > arr[k + 1] for even
Constraints:
arr.length
arr[i]