Sorted Pair Sum

Two Pointer Array Holiday Algorithm

Problem: Sorted Pair Sum

On this holiday season, imagine you're helping Santa match pairs of gift prices that exactly add up to a target amount. Given a sorted array of integers (in ascending order) and a target sum, your task is to determine if there exists a pair of numbers in the array that adds up to the target. If such a pair exists, return their indices (0-indexed). If no such pair exists, return [-1, -1].

Requirements

  • Use the two-pointer technique to achieve an optimal solution.
  • The array is sorted in ascending order.
  • There will be at most one valid pair.

Example

Given: arr = [1, 2, 3, 4, 6] and target = 6
Output: [1, 3]
Explanation: 2 (index 1) + 4 (index 3) = 6.

Starter Code

Below is the starter code for various languages to help you begin your solution.