Return the second largest different value in nums. Repeats of the largest value don't count.
secondLargest([4, 9, 9, 2]) returns 4.
There are always at least two different values. Bonus: can you do it in one pass through the list, without sorting?
nums has up to 5,000 numbers, and any int value is possible.
Input: secondLargest([4, 9, 9, 2])
Output: 4
Input: secondLargest([1, 2])
Output: 1
Your solution is checked against 2 example tests and 5 hidden tests (edge cases and bigger inputs).
Languages you don't learn in class are worth more: C++ 1.25×, JavaScript, TypeScript, C, Rust and Go 1.5×. Your first solve in a language unlocks its "Learned" achievement: +25 for learning it.
Loading editor...
Run Code checks the example tests. Submit runs every test, including hidden ones.