Algorithms Playbook
← All problems
EasyHash maps →Similar to: Two Sum

Pair that adds up

Problem

Given an array of integers nums and an integer target, return the indices of the two numbers that add up to target. Exactly one solution exists and you can't use the same element twice.

Examples

Input: nums = [8, 3, 11, 5], target = 14

Output: [1, 2]

3 + 11 = 14.

Input: nums = [3, 3], target = 6

Output: [0, 1]

Hints

    Try it first. Every hint reveals a bit more.

    Solution