Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Second Largest Without Sorting

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

Your question is Second Largest Without Sorting. 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

How would you find the second largest number in an unsorted array without using built-in sort functions?

Implement the function below to return the second distinct largest integer. The input contains at least two distinct values, and the result must be found without sorting or other built-in ordering functions.

Input: An array of integers.

Output: The second distinct largest integer.

Constraints

  • 2 <= nums.length <= 10^4
  • -10^9 <= nums[i] <= 10^9
  • The array contains at least two distinct integers
  • Do not use sorting or built-in ordering functions

Function Signature

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