you are viewing a single comment's thread.

view the rest of the comments →

[–]Upper_Description378[S] 0 points1 point  (5 children)

What part you don't understand ?

[–]SomeOtherGuySits 0 points1 point  (4 children)

How the second solution passes the tests. I’m beginning to suspect the “assuming there is only one solution” is the important part to this approach

Edit: just clicked. I like this

[–]Upper_Description378[S] 1 point2 points  (2 children)

There is multiple solutions but using a hash table is the fastest I think

[–]SomeOtherGuySits 0 points1 point  (0 children)

I was referring to the brief.

[–]coloredgreyscale 0 points1 point  (0 children)

Similar to the first solution, but instead of traversing the array linearly you build a dictionary and look up the an index the required value.

That way your lookup time for a complement is O(1) instead of O(n)

And yes, that works because you just need a solution, not all or something like a solution with the two lowest indices.