Find 3rd smallest
Input
nums = [7, 10, 4, 3, 20, 15], k = 3
Output
7
Sorted order is [3,4,7,10,15,20]; the 3rd smallest is 7.
Full lesson preview
Select the k-th smallest element in unsorted arrays using the Quickselect algorithm.
Problem statement
Task
Examples
Input
nums = [7, 10, 4, 3, 20, 15], k = 3
Output
7
Sorted order is [3,4,7,10,15,20]; the 3rd smallest is 7.
Input format
Output format
Constraints
Samples
Input
kth_smallest([3, 1, 2, 4], 1)
Output
1
Smallest element is 1.