FunctionRacerProblemsRace

Peak So Far

BeginnerArraysPython, JavaScript, TypeScript, Java, C++

readings lists sensor readings in the order they were taken. Build a new list of the same length where item i is the highest reading among readings[0] through readings[i], the current reading included.

Return that list. An empty readings gives an empty list. Do not change readings.

Example 1

readings [3,1,4,1,5]
returns [3,3,4,4,5]

The highest reading seen so far is 3, then still 3, then 4 (the 4 beats it), still 4, then 5.

Example 2

readings [-2,-5,-1]
returns [-2,-2,-1]

Every reading is negative; the record only moves when a reading beats the previous record, so -1 replaces -2 at the end.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Arrays problems