QuickSelect
ARRAY

Problem

Given an unsorted array nums and an integer k, find the Kth largest element in the array without sorting the entire array. The function should efficiently identify the element corresponding to the Kth position in the descending order of the array elements, without rearranging the array itself.

Examples

quickSelect([1,3,2,0,3,3,3], 2) // returns 3 // The reordered array is [3,3,3,3,2,1,0] from largest to smallest. // The 2nd largest element in the array is 3. quickSelect([1,3,8,9,4,2,3], 3) // returns 4 // The 4th largest element in the array is 4.
Loading...