Objective
Create a Python program that finds two numbers in a sorted list that add up to a given value, using the two-pointer technique.
Instructions
- Read a line with integers sorted from smallest to largest and, on the next line, the target sum.
- Use
i = 0(start) andj = len(list) - 1(end). Whilei < j: computes = list[i] + list[j]. Ifsis the target, finish; if it is smaller, moveiforward; if it is larger, movejback. - If you find the pair, show
Pair: a + b = targetwith the first one this procedure finds. Otherwise, showNo pair.
1 3 4 6 8 11
10
Pair: 4 + 6 = 10
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise