Second Largest

L2 Easy Arrays & Hashing
Concept
Tracking two running champions instead of one lets you answer "what comes after the best?" in a single pass.
Return the second largest *distinct* value in nums. If the array has fewer than two distinct values, return nil.
Examples
▸ nums = [3, 1, 4, 1, 5, 9, 2, 6]
→ 6
▸ nums = [1, 2]
→ 1
▸ nums = [5, 5, 5]
→ nil
Progressive Hints
Hint 1 · Nudge
You need two leaders now: the best so far, and the best of the rest.
Hint 2 · Plan
Track both the largest and the second largest value. When a new value arrives, first check whether it deserves the second spot, then whether it deserves the crown, passing the old crown down as you go. Careful with duplicates: equal values shouldn't create a fake second.
Hint 3 · Approach
Keep biggest and second from the first two distinct values. For each n: if n is bigger than the current biggest, second takes the old biggest and n takes the crown. Otherwise, if n is bigger than second and not equal to biggest, n becomes second. Return second (or nil when there aren't two distinct values).
Output
// Run your code to see the output here.