BT Group interview question

Find the k-th largest element in an array

Interview Answer

Anonymous

13 Nov 2024

I explained and implemented the approach using a min-heap, where I first built a heap of size k with the first k elements and then replaced the smallest element in the heap with any larger element from the remaining array, ultimately finding the k-th largest element at the root of the heap.