Loading...
Loading...
Loading...
A customer wants to buy exactly two different items from a list of prices and spend exactly the budget. Two items can have the same price, but one item cannot be used twice.
YES if two items (at different positions) add up to B, otherwise NO.Example
Input
5 100 40 60 25 75 35
Output
YES
40 + 60 = 100.
Try the problem first. Open one hint at a time.
For each price p, check whether B - p was seen earlier, then add p.
Check before adding, so one item is never paired with itself.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor