A lab scoreboard holds n marks (values may repeat). You need the k-th lowest mark in sorted order, where duplicates count by multiplicity: if the sorted marks are 2 2 4, then the 1st and 2nd lowest are both 2 and the 3rd lowest is 4.
Report the value that would sit at position k (1-indexed) if the marks were sorted ascending. The intended approach partitions the marks around a pivot and recurses only into the side that contains position k, rather than fully sorting.
Line 1: two integers n and k.
Line 2: n space-separated integers, the marks.
A single integer: the k-th lowest mark.
Example 1
Input
5 2 7 3 9 1 4
Expected
3
Explanation
Sorted the marks are 1 3 4 7 9, so the 2nd lowest is 3.
Example 2
Input
6 6 4 4 2 8 2 6
Expected
8
Explanation
Sorted the marks are 2 2 4 4 6 8, so the 6th lowest is 8.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →