Given a sorted array of integers (which may include duplicates) and a target sum, write a function that returns all unique pairs of numbers whose sum equals the target. Each pair should be included only once. For example, even if the same two numbers appear multiple times in the array, they should contribute to a single pair in the result.
Use the two-pointer technique to achieve an optimal solution with O(n) time complexity.
For the input array [1, 1, 2, 2, 3, 4, 5]
and target 6
, the expected output is:
[[1, 5], [2, 4]]
Happy coding and enjoy solving today's challenge on this fine February 5th!