Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

1. Two Sum

EasyDay 1 of 60Arrays & Hashing

Given an array of integers nums and an integer target, return the indices of the two numbers that add up to target. Exactly one valid pair exists, and you may not use the same element twice. Return the two indices in any order.

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]
Constraints
  • 2 <= nums.length <= 10^4
  • -10^9 <= nums[i], target <= 10^9
  • Exactly one answer exists
Hints
Frequently asked at: Amazon, Google, Microsoft, Meta, Adobe, TCS, Infosys
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min