Maximum elevation drop
Your road-trip app records the elevation (in meters, an integer) at each waypoint in order. Riders want to know the biggest single descent available: the largest value of an earlier waypoint's elevation minus a later waypoint's elevation. The two waypoints need not be adjacent, but the higher one must come first. Return that maximum drop, or 0 if the route never descends (or has fewer than two waypoints). For example, [100, 80, 120, 60] gives 60 (120 down to 60).
Implement
biggest_descent(elevations: list[int]) → intExamples
in
[[100,80,120,60]]out60in
[[1,2,3]]out0What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 10 min
solution.py
InputExpectedGot
[[100,80,120,60]]60not run yetsample[[1,2,3]]0not run yetsample