Tech
Kth Largest Element | Heaps
Problem Statement
Given an integer array nums and an integer k , return the kth largest element in the array.
Note:
Not the kth distinct element.
Brute Force Intuition
In an interview, you can explain it like this:
Sort the entire array in descending order and return the kth element.
Complexity
Time Complexity: O(N log N)
Space Complexity: O(1)
Brute Force Code
Arrays . sort ( nums );
return ...
Read the full discussion on Dev.to
This article was aggregated from Dev.to. Click to join the conversation.
View on Dev.to