P02PythonBeginnerInterpret8 min

Find the Second Largest Value

Find the runner-up value in a list without treating repeated maximum values as a new rank.

#lists#edge cases#ranking

Scenario

A weekly sales summary needs the second-highest distinct order total, not the second item after sorting duplicate orders.

Problem statement

Return the second largest distinct numeric value. Decide what your function should do when fewer than two distinct values exist.

Your Task

  1. Make the distinct-value requirement explicit.
  2. Use an approach that is easy to explain in an interview.
  3. Handle an input such as [12, 12, 7].

Input

order_totals = [120, 450, 450, 75, 310]

Related Concepts

SortingSetsAlgorithmic tradeoffs

Ready to count this problem?

Mark it complete when you have reasoned through the solution in your own words.