Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Find Second Maximum in Array

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

Your question is Find Second Maximum in Array. 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 maximum element of an array?

Implement the solution for an array of integers and return the second largest distinct value. Assume the array contains at least two distinct elements. The function should run in linear time and use constant extra space.

Constraints

  • 2 <= nums.length <= 1000
  • -10^9 <= nums[i] <= 10^9
  • The array contains at least two distinct values
  • The result is the second largest distinct value

Function Signature

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