No label this time
Think about a race. You can follow the whole race with just two boxes: one for the winner so far, one for the runner-up so far. When a new runner beats the winner, the old winner becomes the runner-up. When someone lands between the two, they take the runner-up spot.
A small hint for this one. Duplicates don't count twice: in a list where the biggest value appears two times, the second biggest is the next different value.
Before coding: what must you remember as you walk the list?
The second largest in [4, 9, 2, 9, 7]
4
09
12
29
37
4x
- x
- 4
- first
- 4
- second
- -1
Start with first and second both at -1, meaning nothing yet. 4 is bigger than first, so first is 4. The old first, -1, becomes second.
Move 1 of 5