Loading...
Loading...
Loading...
Find two different positions i < j whose amounts add up to a target. If several pairs exist, print the one with the smallest i, and for that i the smallest j. Print i j. If there is no pair, print No pair.
i j (starting from 0), or No pair.Example 1
Input
4 2 7 11 15 9
Output
0 1
2 + 7 = 9, at positions 0 and 1.
Example 2
Input
3 1 2 3 10
Output
No pair
No pair adds to 10.
Try the problem first. Open one hint at a time.
Try each position i, then every later position j, and stop at the first pair that works.
Start j at i + 1 so a value is never paired with itself.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor