← Mock Hub|

FAANG DSA 45-Min Screening

L5
Stage 1 of 4: Stage 1: Clarification & Constraints
Stage: 00:00 / 5:00Total: 00:00 / 45:00

Two Sum

Difficulty: easy · Topic: hashing

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, and you may not use the same element twice. Return the indices in ascending order.

twoSum([2, 7, 11, 15], 9) -> [0, 1]

The obvious approach compares every pair, which is O(n²). There is an O(n) way.