Practice arena
C++17·2 s·128 MB
SortingChallenge
Kth smallest
Find the kth smallest value without fully sorting the input. k is one-based and duplicates count as separate positions.
Input
- — The first line contains T.
- — Each case contains n and k, followed by n integers.
Output
Print one kth-smallest value per case.
Technique
quickselect partition
Target
O(n) average
Constraints & sample
- 1 ≤ k ≤ n ≤ 200,000
- Values fit in a signed 32-bit integer
Sample input
3 6 2 7 10 4 3 20 15 5 3 5 5 1 2 9 1 1 -8
Expected output
4 5 -8
Before you submit
- Test the smallest valid input and one awkward edge case.
- Keep the solution within O(n) average.
- Match spacing and line breaks exactly before checking 8 hidden cases.
Draft saved locally · 441 / 30,000
Ln 1, Col 1Spaces: 4UTF-8LFC++17
Visible testcases
Editable and stored only in this browser. Hidden judge cases never change.
Checking your session…
Run checks Sample · Submit checks 8 hidden cases
Run the sample first, then send your solution through 8 hidden cases.
Code runs in an isolated Judge0 environment. Drafts and custom visible cases stay on this device; submission metadata and progress sync to MongoDB.