Question bank › Prefix Sum
Dsa Prefix Sum Warm-up

The High Altitude Hiker

A hiker starts at an altitude of 0 meters. They follow a trail with N segments, where each segment is described by a change in altitude (positive for uphill, negative for downhill). Find the maximum altitude the hiker reaches at any point during their hike, including the starting point (0). Input Format: The first line contains an integer N. The second line contains N integers representing the altitude change of each segment. Output Format: A single integer representing the maximum altitude reached. Example: Input: 5 10 -5 20 -30 5 Output: 25 (Explanation: Altitudes: Start=0, Seg1=10, Seg2=5, Seg3=25, Seg4=-5, Seg5=0. Max is 25.)

Key concepts

prefix_sumrunning_maximum

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.