LeetCode 1 Two Sum - Problem Statement

The problem

Let's start by looking at LeetCode 1 Two Sum.

You're given an array of integers nums and a target. Your task is to return the indices of two numbers that add up to target.

For example, if nums = [2,7,11,15] and target = 9, you'd return [0,1], since 2+7=92 + 7 = 9.

Before moving to the next unit, think about this: brute force checks every pair in O(n2)O(n^2). What data structure lets you check whether the complement (target - nums[i]) exists in O(1)O(1) average time? This is the key idea behind the classic Two Sum hash map approach.

Constraints: 2n1042 \le n \le 10^4, values from 109-10^9 to 10910^9.