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:
Happy April Fools' Day! No tricks here—just a fun, straightforward two-pointer problem to sharpen your skills!