FreeCareerPath
Build the PrimitiveMedium

Kth Largest Element in an Array

Write `find_kth_largest(nums, k)` returning the kth largest value (1-indexed). Duplicates count separately, so in `[3,3,1]` the 2nd largest is `3`. Sorting is O(n log n) and a size-k heap is O(n log k) — both acceptable. The answer that lands is quickselect: partition around a pivot and recurse into only the side that can contain the answer, O(n) average. Say the worst case is O(n^2) and that a random pivot is what avoids it.

What to expect: A timer starts when you begin. Edit the starter code, run it against the test suite as many times as you like, then finish when you're done. The reference solution and interviewer follow-up questions unlock only after you finish.

Log in to start this session

Timed sessions and your results for "Kth Largest Element in an Array" are saved to your account — logging in takes a few seconds.

Kth Largest Element in an Array — FreeCareerPath