A shop lets customers build a bundle from any non-empty group of items in prices. A bundle qualifies for a promotion when its cheapest item plus its most expensive item is at most limit. A bundle of one item counts its price twice.
Write countBundles(prices, limit) that returns how many different bundles qualify. Two bundles are different if they contain a different set of indexes, even when prices repeat. The count can be huge, so return it modulo 1000000007.
Input: prices = [3,5,6,7], limit = 9 Output: 4
[3], [3, 5], [3, 6], and [3, 5, 6] qualify. For example [3, 6] has 3 + 6 = 9.
Input: prices = [3,3,6,8], limit = 10 Output: 6
[3], [3], [3, 3], [3, 6], [3, 6], and [3, 3, 6].
0 <= prices.length <= 1000001 <= prices[i], limit <= 10^6Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #105 Bundles Where Cheapest and Priciest Fit. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.