Pair Sum Finder

Two Pointer Algorithm Coding

Problem Description

Given a sorted array of integers nums and an integer target, write a function pairSum that finds a pair of numbers in the array whose sum equals target. Use the two-pointer technique to achieve an O(n) time complexity.

If such a pair exists, return the pair as a two-element array (order doesn't matter). If no valid pair exists, return an empty array.

Example:

  • Input:
    • nums = [1, 3, 4, 5, 7, 10]
    • target = 9
  • Output:
    • [4, 5] (or [5, 4])

Happy April Fools' Day! No tricks here—just a fun, straightforward two-pointer problem to sharpen your skills!