easy +10 pts

Running Maximum

Compute the cumulative maximum of a sequence of numbers.

Write a function `running_maximum(numbers)` that takes a list of numbers and returns a new list of the same length where each element at index `i` is the maximum of all elements from index `0` up to `i` inclusive. The input list will not be empty. The function should not modify the input list.

Constraints

Input list length is between 1 and 1000. Numbers can be any integers or floats. Time complexity O(n) where n is the length of the list.

Example

>>> running_maximum([3, 1, 4, 1, 5])
[3, 3, 4, 4, 5]
>>> running_maximum([-2, -5, -1])
[-2, -2, -1]
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Think of keeping a variable that holds the largest number seen so far.
Initialize the variable with the first element.
Iterate through the list, updating the variable and appending it to the result.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.