Track the record high price on every day

Write codeEasy10 min

Your task

Wholesale electricity prices change every day, and they can drop below zero when supply far outruns demand. A trading dashboard shows, for each day, the highest price seen so far.

Write record_highs(prices) that returns that record high for every day.

Input and output:

  • prices: a list of up to 100,000 daily prices in date order, each an integer between -1,000,000 and 1,000,000. It may be empty.
  • Returns a list of integers, the same length as prices.

Rules:

  • Position i of the result holds the highest price from day 0 to day i, including day i itself.
  • An empty list returns an empty list.

Examples

record_highs(prices: list[int]) -> list[int]
Example 1
Inputrecord_highs([3, 1, 4, 2, 6])
Output[3, 3, 4, 4, 6]
Example 2
Inputrecord_highs([-5, -8, -2, -9])
Output[-5, -5, -2, -2]
Example 3
Inputrecord_highs([0, -3, 4, 4, -1])
Output[0, 0, 4, 4, 4]