The problem. Given an integer array nums and an integer k, return the kth largest element — the one that would sit at position k if the array were sorted from largest to smallest. Duplicates count: in [3, 3, 1] the 2nd largest is 3. Can you do it without fully sorting?
Input: nums = [3, 2, 1, 5, 6, 4], k = 2
Output: 5
Input: nums = [3, 2, 3, 1, 2, 4, 5, 5, 6], k = 4
Output: 4 largest first: 6, 5, 5, 4, ...Free account
Sign up to read the rest of this lesson: 5 more sections, 3 drawings, a dry-run simulator and code in JavaScript, Python, Java and C++.
Still to come