Target Sum Pair Finder

Two Pointer Array Coding Challenge

Problem Description

You are given a sorted array of integers (in ascending order) and a target integer. Your task is to find two distinct numbers in the array that add up to the target integer using the two-pointer technique. If a valid pair is found, return their indices (0-based); if no such pair exists, return an empty list.

Input

  • A sorted array of integers.
  • A target integer.

Output

  • An array containing the indices of the two numbers that add up to the target. If no valid pair exists, return an empty array.

Example

Input: nums = [1, 2, 3, 4, 6], target = 6
Output: [1, 3]  // because nums[1] + nums[3] = 2 + 4 = 6

Constraints

  • Use the two-pointer technique to achieve O(n) time complexity.

Holiday Note

On December 10, 2024, as the festive season approaches, enjoy solving this challenge and celebrate your coding progress!