Skip to main content
Admissions guidance, study banks, and career tools — get started on Shalyam

Two Sum

Easy Arrays

Given an array of integers nums and an integer target, find the two numbers whose sum equals target and print their indices. Exactly one valid pair exists and the same element cannot be used twice. Print the smaller index first.

Constraints

2 <= n <= 10^5 -10^9 <= nums[i], target <= 10^9 Exactly one solution exists

Discussion

No discussions yet.

Rewards · v2.1

Get Exclusive Insights with Every Issue

Join Shalyam Newsletter

Stay ahead in education, research, and innovation—straight to your inbox.