K Cheapest Phone and Accessory Combo Bundles
Last updated: November 29, 2026
Quick Overview
Given two price lists sorted ascending, one for phones and one for accessories, return the K cheapest (phone, accessory) bundles by total price without generating every combination.
Flipkart
November 29, 20260
0
0 solved
Given two price lists sorted ascending, one for phones and one for accessories, return the K cheapest (phone, accessory) bundles by total price without generating every combination.
A Flipkart onsite heap question built around combo offers on the product page ('frequently bought together'). The interviewer checks that you avoid the n*m blowup and use a min heap frontier over the implicit sorted matrix of sums.
What the Interviewer Expects
- Notice that all n*m sums form a matrix sorted along rows and columns
- Seed a min heap with the first accessory for each of the first K phones
- Push the next accessory for a phone each time its bundle is popped
- State O(K log K) time
- Handle K larger than n*m and empty lists
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you find only the Kth cheapest total without listing all K?
- What if there are three lists (phone, case, charger)?
- How would you dedupe bundles with the same total price for display?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Inputs:
phones(length n) andaccessories(length m), both sorted ascending; integerK. - Output: up to
Kpairs in nondecreasing order of total price. - n and m can be 10^4 each, so n*m = 10...
High-Level Design
Picture the sums as a grid where row i is a phone and column j an accessory. Every row is sorted and every column is sorted. The cheapest unseen bundle is always the next element of some row. So r...