Tap here to switch tabs
Problem
Submissions

Problem: Longest Mountain in Array

med
30 min
Try to solve the Longest Mountain in Array problem.

Statement

Given an integer array arr, return the length of the longest contiguous subarray that forms a mountain.

A subarray arr[l..r] is a mountain if all of the following are true:
A mountain has length at least 33.
There exists an index p with l < p < r such that arr[l] < arr[l+1] < ... < arr[p] and arr[p] > arr[p+1] > ... > arr[r].
In other words, the values strictly increase up to a single peak, then strictly decrease after the peak.

If no mountain exists in arr, return 00.

Note: Consider whether you can solve this in a single pass using O(1)O(1) extra space.

Constraints:

  • 1≤1 \leq arr.length ≤104\leq 10^4

  • 0≤0 \leq arr[i] ≤104\leq 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Longest Mountain in Array

med
30 min
Try to solve the Longest Mountain in Array problem.

Statement

Given an integer array arr, return the length of the longest contiguous subarray that forms a mountain.

A subarray arr[l..r] is a mountain if all of the following are true:
A mountain has length at least 33.
There exists an index p with l < p < r such that arr[l] < arr[l+1] < ... < arr[p] and arr[p] > arr[p+1] > ... > arr[r].
In other words, the values strictly increase up to a single peak, then strictly decrease after the peak.

If no mountain exists in arr, return 00.

Note: Consider whether you can solve this in a single pass using O(1)O(1) extra space.

Constraints:

  • 1≤1 \leq arr.length ≤104\leq 10^4

  • 0≤0 \leq arr[i] ≤104\leq 10^4