Given a list of integers, your task is to output the second largest value in the first k elements, for each k between 2 and the length of the input list.
In other words, output the second largest value for each prefix of the input.
You can output an arbitrary value for the first element (where k = 1), or simply omit this value, as there isn't a second maximum for a list of 1 element. You may assume there are at least 2 elements in the input.
Shortest code wins.
Examples
Input:
1 5 2 3 5 9 5 8
Output:
1 2 3 5 5 5 8
Input:
1 1 2 2 3 3 4
Output:
1 1 2 2 3 3
Input:
2 1 0 -1 0 1 2
Output:
1 1 1 1 1 2
k
determined? \$\endgroup\$1
is not, strictly speaking, the second largest value of1,1
(2nd example) it's the second value when sorted descending. \$\endgroup\$-1, 0, 0, 1, 1, 2
for the last test case.) \$\endgroup\$