Find the Highest Altitude
EasyArrays & Hashingprefix sum
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 cyclist rides a route of n + 1 points, starting at point 0 with altitude 0. You are given an array gain of length n, where gain[i] is the change in altitude from point i to point i + 1.
Return the highest altitude reached at any point, including the starting point.
Examples
Input: gain = [-5,1,5,0,-7]
Output: 1
The altitudes are [0,-5,-4,1,1,-6]; the highest is 1.
Input: gain = [-4,-3,-2,-1,4,3,2]
Output: 0
The route never climbs above the start at 0.
Constraints
- n == gain.length
- 1 <= n <= 100
- -100 <= gain[i] <= 100
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.