AnswerBox
Python

Two Sum

Description:
Given an array of integers and a target, return indices of two numbers that add up to target.
Python Code
def twoSum(nums, target):
    seen = {}
    for i, num in enumerate(nums):
        diff = target - num
        if diff in seen:
            return [seen[diff], i]
        seen[num] = i
    return []

print(twoSum([2, 7, 11, 15], 9))
Expected Output
[0, 1]