collections/quickselect_utils library
Quickselect: the k-th smallest/largest element without fully sorting. Roadmap #52.
Functions
-
nthLargest<
T> (Iterable< T> items, int k, Comparator<T> compare) → T? -
Returns the
k-th largest element (0-based:k = 0is the maximum), ornullifkis out of range. Equivalent tonthSmallestfrom the other end. Audited: 2026-06-12 11:26 EDT -
nthSmallest<
T> (Iterable< T> items, int k, Comparator<T> compare) → T? -
Returns the element that would sit at 0-based index
kifitemswere sorted bycompare, without paying for a full sort.