by dithering · 9y ago · 0 comments
You can also stop when you hit Nmax-K... might save a few lookups when K is large.
If you're setting the value in the hash table as you check it (as you would in a single pass), you have to do n-k as well.
This is because the number you are currently adding didn't exist in the array when you checked n+k for the previous numbers.