Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Second Largest Number

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Second Largest Number. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Motorola MOTOTRBO telemetry processing may need to identify the second highest reading from a batch of numeric measurements. Given a list of integers, return the second largest distinct value without sorting the list.

Formal Specification

Implement find_second_largest(nums). The input is a non-empty list of integers containing at least two distinct values. Return one integer: the second largest distinct value in nums.

Duplicate occurrences of the largest value do not count as the second largest value. The input list must not be modified.

Constraints

  • 2 <= len(nums) <= 10^5
  • -10^9 <= nums[i] <= 10^9
  • nums contains at least two distinct values
  • The input list must not be modified

Function Signature

def find_second_largest(nums):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output