FreeCareerPath
Build the PrimitiveEasy

Two Sum

Write `two_sum(nums, target)` that returns the indices of the two values summing to `target`, as a tuple `(i, j)` with `i < j`. Exactly one such pair exists. two_sum([2, 7, 11, 15], 9) -> (0, 1) two_sum([3, 3], 6) -> (0, 1) The trick is a map from value to index built as you go. Look up the complement *before* inserting the current value, or a single element will pair with itself.

What to expect: A timer starts when you begin. Edit the starter code, run it against the test suite as many times as you like, then finish when you're done. The reference solution and interviewer follow-up questions unlock only after you finish.

Log in to start this session

Timed sessions and your results for "Two Sum" are saved to your account — logging in takes a few seconds.

Two Sum — FreeCareerPath