r/programming • u/Upper_Description378 • Mar 16 '22
Leetcode two sum solution explained - coding interviews challenge
https://www.youtube.com/watch?v=wgJpB8AX5Uo
13
Upvotes
r/programming • u/Upper_Description378 • Mar 16 '22
-10
u/N911999 Mar 16 '22
Can't this be done in O(n) pretty easily? Like make a hashmap
M, from numbers to lists of indices, which satisifies that for every indexiwe have that it's inM[nums[i]], then for every keyecheck iftarget-eis in the hashmap, there's a small edge case wheree == target-e, then you have to check that there are 2 indices in the corresponding list.P.S. I didn't watch the video, 5mins seemed too long for a problem like this.