Practice ยท 1 of 3
Sorted Pair Sum
Implement static int[] pairWithSum(int[] sorted, int target) โ
return the two INDICES (ascending) of a pair summing to target, or null
when none exists. Use two pointers โ the sorted order is your invariant.
Examples: [1,3,5,8], target 8 โ [1,2] (3+5); target 4 โ [0,0] is invalid
(distinct indices only), so null unless a real pair exists. Duplicate
values are allowed as a pair ([3,3], target 6 โ [0,1]).
Difficulty: intermediate
Press Submit to check your solution.
Back to lesson: Practice: Algorithms Lab