Problem statement
Given an array of integers, produce a row where position i holds the largest value from index 0 up to index i.
The row has the same length as the array, and every position is written, not only the last one.
Examples
Inputa = [3, 1, 4, 1, 5, 9, 2]
Outputpre = [3, 3, 4, 4, 5, 9, 9]
Slot 5 raises the running value from 5 to 9, and the last two slots keep it.
Inputa = [9, 7, 5, 3, 1]
Outputpre = [9, 9, 9, 9, 9]
A strictly falling array keeps the first cell as the answer for every prefix.
The walkthrough is part of Premium
The statement and the examples above stay free. The full how-to-solve walkthrough, the cost notes in plain words and the interactive step-by-step visualizer unlock with a Premium plan.
See pricing