"""
Exercise 1: practise the method on Two Sum

Given a list of integers `nums` and an integer `target`, return the indices
[i, j] (i < j) of the two numbers that add up to target. Exactly one answer
exists; you may not use the same element twice.

Follow the method: write the brute force idea in a comment (one line), then
implement the O(n) hash-map version.

  two_sum([2, 7, 11, 15], 9)  -> [0, 1]
  two_sum([3, 2, 4], 6)       -> [1, 2]
  two_sum([3, 3], 6)          -> [0, 1]
"""

def two_sum(nums, target):
    # Brute force: TODO (one line)
    # TODO: one pass with a dict mapping value -> index
    pass


# --- self-check: do not modify below this line ---
cases = [(([2, 7, 11, 15], 9), [0, 1]), (([3, 2, 4], 6), [1, 2]), (([3, 3], 6), [0, 1]),
         (([-1, -2, -3, -4, -5], -8), [2, 4]), (([0, 4, 3, 0], 0), [0, 3])]
ok = True
for args, want in cases:
    got = two_sum(*args)
    print(args, "->", got, "expected", want)
    ok = ok and got == want
big = list(range(200_000))
import time
t = time.perf_counter(); r = two_sum(big, 399_997); el = time.perf_counter() - t
print("large input:", r, f"{el:.3f}s")
ok = ok and r == [199_998, 199_999] and el < 1.0
print("PASS" if ok else "FAIL")
