A store sells bundles of one laptop and one accessory. Laptop prices are in laptops and accessory prices in accessories, both sorted ascending.
Write cheapestPairs(laptops, accessories, k) that returns the k cheapest bundles as [laptopPrice, accessoryPrice] pairs, cheapest first. Order bundles by total price; for equal totals, the one with the smaller laptop index i comes first, and then the smaller accessory index j. If there are fewer than k bundles, return all of them.
Input: laptops = [100,300,500], accessories = [20,40,60], k = 3 Output: [[100,20],[100,40],[100,60]]
Totals 120, 140, 160 are the three smallest.
Input: laptops = [1,2], accessories = [3], k = 5 Output: [[1,3],[2,3]]
Only two bundles exist.
1 <= laptops.length, accessories.length <= 10^51 <= k <= 10^50 <= price <= 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 #390 Cheapest Bundle Pairs. 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.