Link: https://leetcode.com/problems/kth-largest-element-in-an-array/
Solution:
Topics: heap
Intuition
Very simple and classic Kth largest/smallest problem. Simply add every number to a min heap and pop off the top when the size of the heap is greater than k
. Return the top of the heap at the end of the loop.
Implementation
Review 1
Too easy.
Review 2
Counting sort can also be used if we create a bucket for every unique number and set it to true
when said number is seen. The kth
largest would simple then be the kth
index of bucket array that is true
, from the back.