Sorted Pair Sum Finder

Two Pointer Array Search

Sorted Pair Sum Finder

Given a sorted array of integers and a target sum, write a function that uses the two-pointer technique to check if there is a pair of numbers in the array that sums up to the target. If such a pair exists, return the pair as an array (or list) of two numbers; otherwise, return an empty array.

Example

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

    • Output: [2, 4]
  • Input: arr = [2, 5, 9, 11], target = 11

    • Output: []

Notes

  • Utilize the two-pointer technique to achieve an efficient solution.
  • Think about how to move the pointers based on the sum compared to the target.
  • This exercise is a great way to sharpen your two-pointer manipulation skills.

Happy coding!