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.

  1. Sort the array in descending order (b - a).
  2. Print the element at index k-1.

01EXAMPLE 1

Inputnums=[3,2,3,1,2,4,5,5,6], k=4
Output4

Explanation: Sorted: [6,5,5,4,...]. 4th is 4.

Constraints

  • Simple Sort approach for now.
ArraysSortingAlgorithms
JavaScript
Loading...
1 Hidden

Input Arguments

nums[3,2,1,5,6,4]
k2

Expected Output

5

Click RUN to test your solution