Longest Mountain in Array
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
A *mountain* is a contiguous subarray of length at least 3 that strictly increases up to a peak and then strictly decreases, with the peak strictly inside (not the first or last element of the subarray). Plateaus (equal neighbors) break a mountain.
Given an integer array arr, return the length of the longest mountain subarray, or 0 if there is none.
Aim for one pass and O(1) extra space.
Examples
Constraints
- 1 <= arr.length <= 10^4
- 0 <= arr[i] <= 10^4
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.