Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Kth Largest Element
00:00
5 left

Kth Largest Element

EasyPython

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):
Interviewer

Your question is Kth Largest Element. Start with the requirements in the Question tab.

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.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.