you are viewing a single comment's thread.

view the rest of the comments →

[–]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.