Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Kth Largest Element

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

Your question is Kth Largest Element. 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

Given an integer array nums and an integer k, return the kth largest element in the array. The kth largest element is the element that would appear in position k if the array were sorted in descending order.

You must return the value, not the index. Duplicates count as separate elements.

Formal Specification

  • Input:
    • nums, a list of integers
    • k, an integer with 1 <= k <= len(nums)
  • Output:
    • A single integer, the kth largest element in nums

Constraints

  • 1 <= len(nums) <= 10^5
  • -10^9 <= nums[i] <= 10^9
  • 1 <= k <= len(nums)
  • Duplicates are allowed

Function Signature

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