DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
easy
Two Pointer

Two Sum II (Sorted Array)

**Problem Statement:** Given a 1-indexed array of integers `numbers` that is already sorted in non-decreasing order, find two numbers such that they add up to a specific `target` number. Let these two numbers be `numbers[index1]` and `numbers[index2]`. Return the indices of the two numbers. **Hint / Expected Approach:** Converging two pointers **Edge Cases to Consider:** - (1) Only two elements - (2) Sum found at edges - (3) Multiple pairs summing to target

Examples

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

Constraints

  • ▪1 <= data.length <= 10^5
  • ▪Memory complexity must be O(1) or O(k)
  • ▪Ensure non-overlapping pointer access

Watch Out For Edge Cases

  • ▪Only two elements
  • ▪Sum found at edges
  • ▪Multiple pairs summing to target
Frequently Asked At
AmazonMicrosoftGoogleTCS