#1 most askedVery commonEasyHash map
Two Sum
New to Hash map? Learn it from scratch firstHash Maps & Sets โ
๐ข Asked in real interviews
No reports yet. Were you asked this? Be the first to say where.Given a list of numbers nums and a number target, return the indices of the two numbers that add up to target. Each input has exactly one answer, and you can't use the same element twice.
two_sum([2, 7, 11, 15], 9) โ [0, 1] because 2 + 7 = 9.
๐งช Practice
Write your solution, then press Run tests. Explain your approach out loud as you go.
def two_sum(nums, target):
pass
Output appears here. Press Run or Ctrl/โ + Enter.
Try it first. Struggling for a few minutes is how it sticks.