Drill

ProblemsPython › data

The highest so far

easydataPython

A stock chart underlays the running peak: after each point, how far has the price climbed at most.

running_max(values: list<int>) → list<int>

Solve it in the editor →

Where you start

def running_max(values: list[int]) -> list[int]:
    

Worked examples

CallResult
running_max([3, 1, 2])[3, 3, 3]
running_max([1, 2, 3])[1, 2, 3]
running_max([5, -2, 7])[5, 5, 7]
running_max([2, 1, 3, 2])[2, 2, 3, 3]

Hint

Keep one running best and stamp it into the result after considering each value.

Reference solution in Python
def running_max(values: list[int]) -> list[int]:
    best = 0
    started = False
    result = []
    for v in values:
        if not started or v > best:
            best = v
            started = True
        result.append(best)
    return result

The same problem in another language

More data problems in Python