We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Alright, solved it.
I basically just changed my solution to use a two passes rather than one. The first pass to put the values (c) into a map, then I iterate again on the second pass, and just check if the complement exists (c+k).
I think there's some pathologial edge case if you check both ways in a single pass. Not sure if I can prove it, but this solution works, and is (O(2N)) vs O(N).
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Pairs
You are viewing a single comment's thread. Return to all comments →
Alright, solved it. I basically just changed my solution to use a two passes rather than one. The first pass to put the values (c) into a map, then I iterate again on the second pass, and just check if the complement exists (c+k).
I think there's some pathologial edge case if you check both ways in a single pass. Not sure if I can prove it, but this solution works, and is (O(2N)) vs O(N).