Sorted Pair Sum

Two Pointer Array Technique Coding

Sorted Pair Sum

Given a sorted array of integers and a target integer, your task is to find the indices of the two numbers that add up to the target. If no such pair exists, return [-1, -1].

Problem Details:

  • The array is sorted in ascending order.
  • There is at most one pair that sums up to the target.
  • Use the two-pointer technique to achieve an optimal solution.

Example:

Input: nums = [1, 2, 3, 4, 6], target = 6

Output: [1, 3]
Explanation: The numbers at index 1 and index 3 (2 and 4) add up to 6.

Hint:

Initialize two pointers: one at the beginning of the array and one at the end. Move the pointers inward based on the sum compared to the target.

This problem is not only a great exercise in the two-pointer technique but also timely as we celebrate another summer day. Enjoy coding!