DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
easy
Array

Two Sum

**Problem Statement:** Given an array of integers `nums` and an integer `target`, return the indices of the two numbers such that they add up to `target`. You may assume that each input would have exactly one solution, and you may not use the same element twice. **Hint / Expected Approach:** Hash map for O(n) complement lookup **Edge Cases to Consider:** - (1) All negative numbers - (2) Duplicate values where both used - (3) Target = sum of same index element twice

Examples

Example 1
Input: [2, 7, 11, 15], 9
Output: [0, 1]
Example 2
Input: [3, 2, 4], 6
Output: [1, 2]
Example 3
Input: [3, 3], 6
Output: [0, 1]

Constraints

  • ▪1 <= nums.length <= 10^4
  • ▪-10^9 <= nums[i] <= 10^9
  • ▪Time complexity should be O(n) or O(n log n)

Watch Out For Edge Cases

  • ▪All negative numbers
  • ▪Duplicate values where both used
  • ▪Target = sum of same index element twice
Frequently Asked At
GoogleAmazonMicrosoftMetaAdobeFlipkartTCS