Goal
Implement second_largest(nums) so it returns the second-largest distinct value in the list. Use a single pass over the list—do not sort.
Requirements
- One pass only; do not use
sort() or sorted().
- "Second largest" means the second-biggest distinct value. In
[3, 1, 4, 1, 5], the distinct values are 1, 3, 4, 5; the largest is 5 and the second largest is 4.
- If there are fewer than two distinct values, return
None.
Example
second_largest([3, 1, 4, 1, 5]) → 4