Skip to content

Instantly share code, notes, and snippets.

@or9
Created January 2, 2021 23:39
Show Gist options
  • Save or9/a5b4f4cf7cd3d55060b99d97f1375ec0 to your computer and use it in GitHub Desktop.
Save or9/a5b4f4cf7cd3d55060b99d97f1375ec0 to your computer and use it in GitHub Desktop.
Extract the kth element from a list of lists without a heap
function kth (m, k) {
return m.reduce((curr, next) => curr.concat(next))
.sort((x, y) => x >= y? 1: -1)
[k];
}
// e.g., [[1, 5, 9], [10, 11, 13], [12, 13, 15]], 7
@saws1217
Copy link

saws1217 commented Jan 2, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment