Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

nums =
k =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Keep a min-heap of size k with the k largest values.

Approach

Push each number; if heap grows beyond k, pop the smallest. The heap’s root ends as the k-th largest.

Why it works

After processing all values, exactly the k largest remain in the heap; the smallest of them is the k-th largest.

Code
Loading...
Complexity
Time: O(n log k)
Space: O(k)
Solution
Updated: 2026-02-23

Idea

Keep a min-heap of size k with the k largest values.

Approach

Push each number; if heap grows beyond k, pop the smallest. The heap’s root ends as the k-th largest.

Why it works

After processing all values, exactly the k largest remain in the heap; the smallest of them is the k-th largest.

Code
Loading...
Complexity
Time: O(n log k)
Space: O(k)