Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Place one pointer at the start and one at the end of the sorted array. If the sum is too small, advance the left pointer to increase it. If too large, retreat the right pointer to decrease it. This converges on the target pair in one pass.
Sorted order guarantees that moving the left pointer right increases the sum and moving the right pointer left decreases it, so each step provably eliminates at least one candidate pair.
Updated Feb 2026