The Kth Selection
HardAcc. 86.4%
+40 XP 20
Positional Priority
Given an array and an integer k, find the value that would be at the k-th position if the array were sorted from largest to smallest.
The Assignment
Your function receives nums and k.
- Sort the array in descending order (
b - a). - Print the element at index
k-1.
01EXAMPLE 1
Input
nums=[3,2,3,1,2,4,5,5,6], k=4Output
4Explanation: Sorted: [6,5,5,4,...]. 4th is 4.
Constraints
- Simple Sort approach for now.
ArraysSortingAlgorithms
JavaScriptSystem handles I/O — write your function only
Loading...
1 Hidden
Input Arguments
nums[3,2,1,5,6,4]
k2
Expected Output
5
Click RUN to test your solution