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]
.
Given: arr = [1, 2, 3, 4, 6]
and target = 6
Output: [1, 3]
Explanation: 2 (index 1) + 4 (index 3) = 6
.
Below is the starter code for various languages to help you begin your solution.