Two pointers

Which distinct pair reaches the target?

Examples

Worked example

Input
[1, 2, 5, 8], target 7
Expected output
2 + 5

Hints and solution

Hint 1

Write down the starting state and walk through one example by hand.

Reveal worked answer

Start with 1 + 8 = 9 and move right to 5. Then 1 + 5 = 6, so move left to 2 to get 7.

Back to the lesson