The Find the Highest Altitude interview question is a simple tracking task. You start a bike trip at altitude 0. You are given an array gain where gain[i] is the net altitude gain/loss between points and . You need to find the highest altitude reached at any point during the trip.
Companies like Meta and Amazon use this as a warm-up coding question. It tests a candidate's basic understanding of the Prefix Sum interview pattern and their ability to maintain a running maximum. It’s an essential "check" for programming fundamentals.
This problem follows the Prefix Sum and Running Maximum patterns.
currentAltitude = 0, maxAltitude = 0.gain array.currentAltitude.maxAltitude if currentAltitude is larger.maxAltitude.Gains: [-5, 1, 5, 0, -2]
max = 0.max = 0.max = 0.max = 1.max = 1.max = 1.
The highest altitude reached is 1.Always look for ways to optimize space. If you only need to compare the "current" total with a "best" total, you don't need to store all the intermediate totals in a list. This shows a "production-ready" mindset.