Loading...
Loading...
Loading...
A cashier wants two items from a price list whose prices add up to exactly the target. Exactly one pair of positions works. Print the two positions, counting from 0, smaller first.
Example 1
Input
4 9 2 7 11 15
Output
0 1
2 + 7 = 9.
Example 2
Input
3 6 3 2 4
Output
1 2
Try the problem first. Open one hint at a time.
Keep a dictionary from price to position for the items already seen.
For each price x, check whether target - x is already in the dictionary before you add x.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor