Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Second largest order total

Python data engineering interview problem. Difficulty: beginner. Pattern: Sorting. About 10 minutes. Part of the Pro drill bank.

Finance dumps daily order totals into a list. Reporting wants the second-highest distinct amount so they can compare the runner-up basket to the winner, even when many orders share the top value.

Return the second-largest distinct number from a list of order totals.

Requirements

  • Ranking is over distinct values, not over list positions.
  • If fewer than two distinct values exist, return None.

Constraints

  • Negative totals can appear.

Examples

Input: second_largest([1, 5, 5, 3]) Output: 3 This input follows the stated rules and produces this output.

Topics: lakebench, python, lists.

More Python interview questions · All interview problems · Learn data engineering

beginner

Second largest order total

Interview-style drill: Given a list of order totals, return the second-largest distinct value.

Return the second-largest distinct number from a list of order totals.