"""
https://leetcode.com/problems/two-sum/description/
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
You can return the answer in any order.
"""
from typing import List
def two_sums(arr: List[int], target: int) -> List[int]:
values = {} # value -> index in arr
for i, value in enumerate(arr):
value_needed = target - value
if value_needed in values:
return [values[value_needed], i]
else:
values[value] = i
raise RuntimeError("not reachable")