Lesson 1 of 4
Live algorithm trace
Two Sum on sorted input
Complete execution1 of 4
Two plus 15 is too large.
1
left = 0; right = length - 12
total = numbers[left] + numbers[right]3
if total == target: return [left + 1, right + 1]4
if total < target: left += 15
else: right -= 1target = 9total = 17
This time the stones are already sorted. That order is a compass: place one sentinel at each edge and let the sum tell you which one must move.