This question evaluates array manipulation, selection algorithms, in-place partitioning techniques, and complexity analysis within the domain of coding and algorithms.
You are given an unsorted array of integers nums and a positive integer k.
Design an efficient algorithm to find the k-th largest element in the array. The k-th largest element is the element that would appear in position len(nums) - k if the array were sorted in non-decreasing order.
nums = [3, 2, 1, 5, 6, 4]
,
k = 2
5
(the sorted array is
[1, 2, 3, 4, 5, 6]
, so the 2nd largest is 5)
Assumptions and requirements:
1 <= k <= len(nums)
.
Tasks: