Editor

Second Largest Value

#243 · Lists · Beginner · 35 XP · about 6 min

Write second_largest(nums) that returns the second largest different value in a list of numbers. Repeats of the largest value do not count: in [7, 7, 5] the largest value is 7 and the second largest is 5.

If the list has fewer than two different values, there is no second largest, so return None.

Examples

second_largest([3, 7, 5])  # returns 5
second_largest([7, 7, 5])  # returns 5
second_largest([4, 4])     # returns None

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.