Two Pointers (pair sum) Playground

Dodi and Jaya from the two ends of the floor: how many weighings until a pair of sacks matches the target, against nested loops and a Map that really run?…

Why it matters

The two-pointer pattern turns up in many problems: a pair summing to a target, dropping duplicates, reversing an array, merging two sorted lists. It is O(n) time and O(1) memory, but only when the order makes every step throw something away for sure.

The key idea

Every weighing throws away one sack with all its pairs

Common mistakes

Try it in this playground