K Nearest Values — Solution & Editorial
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)
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)