Data Structures19 sections · 729 units
Open in Course

The Pair Finding Problem

A quadratic trap

New problem: given a sorted array, find two numbers that sum to a target. Brute force: check all pairs. That's O(n2)O(n^2). There's a technique that solves this in O(n)O(n) with no extra space. It's called two pointers, and it's one of the most useful patterns in competitive programming.