Practice Shopping Offers
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Shopping Offers
Problem Statement
In LeetCode Store, there are n items to sell. Each item has a price. However, there are some special offers, and a special offer consists of one or more different kinds of items with a sale price. You are given an integer array price where price[i] is the price of the ith item, and an integer array needs where needs[i] is the number of pieces of the ith item you want to buy. You are also given an array special where special[i] is of size n + 1 where special[i][j] is the number of pieces of the jth item in the ith offer and special[i][n] (i.e., the last integer in the array) is the price of the ith offer. Return the lowest price you have to pay for exactly certain items as given, where you could make optimal use of the special offers. You are not allowed to buy more items than you want, even if that would lower the overall price. You could use any of the special offers as many times as you want.
Source: Shopping Offers on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
price = [2,5], special = [[3,0,5],[1,2,10]], needs = [3,2]
14
# Example 2
price = [2,3,4], special = [[1,1,0,4],[2,2,1,9]], needs = [1,2,1]
11
Constraints
Related LeetCode Problems
Practice more problems similar to Shopping Offers.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.