All problems
0162EasyArrayPrefix Sum

Climb Altitude Log

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1480Running Sum of 1d Array

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A trekking watch splits a walk into legs and stores one signed altitude change per leg in deltas, measured in metres. A positive entry is a climb, a negative entry is a descent, and a zero entry is flat ground.

The watch starts the walk at altitude 0. Build the log the walker actually wants: an array of the same length whose entry i is the altitude reached once leg i has been finished, which is the sum of deltas[0] through deltas[i].

Altitudes may sit below the starting point, so entries in the answer can be negative.

Examples

Example 1

Input
deltas = [12, -5, 40, 0]
Output
[12, 7, 47, 47]

After the first leg the walker is 12 metres up, the descent brings that to 7, the long climb takes it to 47, and the flat leg leaves it there.

Example 2

Input
deltas = [-3, -3, -3]
Output
[-3, -6, -9]

Every leg drops three metres, so the log runs steadily below the starting altitude.

Example 3

Input
deltas = [7]
Output
[7]

A single leg gives a single altitude, which is that leg's own change.

Constraints

  • 1 <= deltas.length <= 1000
  • -10^6 <= deltas[i] <= 10^6

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def altitude_log(deltas: list[int]) -> list[int]:
Java
public int[] altitudeLog(int[] deltas)
September 7
Apply