Maximum elevation drop

Write codeEasy10 minAmazon style

Your task

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).

Examples

biggest_descent(elevations: list[int]) -> int
Example 1
Inputbiggest_descent([100, 80, 120, 60])
Output60
Example 2
Inputbiggest_descent([1, 2, 3])
Output0