This problem is a gateway to understanding quickselect — the O(n) average-case selection algorithm based on quicksort's partition.
Enable JavaScript for the full StreamPrep guide.