Two Sum

Given an array of integers nums and an integer target, return the indices of the two numbers that add up to target. Each input has exactly one solution. You…

Given an array of integers `nums` and an integer `target`, return the indices of the two numbers that add up to `target`. Each input has exactly one solution. You may not use the same element twice.

- `2 <= nums.length <= 10^4` - `-10^9 <= nums[i] <= 10^9` - `-10^9 <= target <= 10^9` - Exactly one valid answer exists. - The interactive visualizer accepts at most 12 values; longer valid arrays are execution-only.

Example 1: input nums = [2,7,11,15], target = 9; output [0,1]. nums[0] + nums[1] = 2 + 7 = 9.

Example 2: input nums = [3,2,4], target = 6; output [1,2]. The matching pair appears after the first value; nums[1] + nums[2] = 2 + 4 = 6.

Example 3: input nums = [3,3], target = 6; output [0,1]. Equal values at two distinct indices form a valid pair.

Category: Arrays & Hashing. Topic: arrays. Difficulty: Easy. Patterns: hashing, two-pointers.