teacher
Sign in

Two Pointers

Walk two indices through an array to replace a nested loop with a single pass.

30 minCF 800–14005 interactive12 problems

The problem

You get a sorted array a of n numbers and a target T. Find two different positions i < j with a[i] + a[j] = T, or report that none exist.

1 of 9