Problems > K Nearest Values > Editorial

K Nearest Values — Solution & Editorial

Back to the Problem

Sort; shrink a window from both ends dropping whichever end is farther (the tie rule drops the larger end), until exactly K remain.

Complexity: O(N log N)