Loading...
Loading...
Loading...
Given n prices and a budget, find two positions i < j with price[i] + price[j] = budget. Choose the pair with the smallest j, and for that j the smallest i. Print i j, or none when there is no pair.
Example
Input
5 17 3 8 12 5 9
Output
2 3
The pair 12 and 5 is completed first, at j = 3.
Try the problem first. Open one hint at a time.
For each price, look up budget - price among the earlier prices.
Store the first index of each price, and look up before storing.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor