Algorithm · Apple · Easy
An array arr qualifies as a mountain array exactly when all of the following hold: Its size is at least 3. There is an index i where 0 arr[i + 1] > ... > arr[arr.length - 1]. Given an integer array arr, determine the maximum length among its contiguous subarrays that form mountains. If none of its subarrays is a mountain, return 0. Examples Example 1: Input: arr = [3,5,6,4,1,2] Output: 5 Explanation: The longest valid mountain is [3,5,6,4,1], so its length is 5. Example 2:…
Checking your access…