Second Largest

Medium20–30 pts depending on language · +25 for learning a language that's new to you

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.

Examples

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).

Solved by 5 members

  1. 1Alex T.Rust · Oct 13
  2. 2brett B.Java · Oct 14
  3. 3Isaac M.Rust · Oct 19
  4. 4CasonRust · Oct 20
  5. 5RainePython 3 · Oct 21
Full leaderboard →

Your Solution

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...

IntelliSense: connecting…

Run Code checks the example tests. Submit runs every test, including hidden ones.