Loading...
Loading...
Loading...
A store has n products with positive prices. A basket is any group of products, and two products with the same price at different positions are different products. Count the baskets whose total price is exactly the target.
Example
Input
4 7 2 3 4 5
Output
2
Baskets {2, 5} and {3, 4}.
Try the problem first. Open one hint at a time.
Sort the prices. Choose products from left to right using a start index.
When a price is larger than what is left, stop the loop: every later price is larger too.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor