You are viewing a single comment's thread. Return to all comments →
Another clear high level way of doing it using javascript:
var hash = x.reduce((prev, next) => { prev[next] = true; return prev; },{}) var result = x.reduce((prev, next) => { return (hash[next+k]) ? prev + 1 : prev; }, 0)
Just need to traverse the list 2 times: O(N)
Pairs
You are viewing a single comment's thread. Return to all comments →
Another clear high level way of doing it using javascript:
Just need to traverse the list 2 times: O(N)