Minimum Cost to Buy Apples
A medium-tier problem at 67% community acceptance, tagged with Array, Graph, Heap (Priority Queue). Reported in interviews at Directi and 1 others.
Minimum Cost to Buy Apples lands in your OA and you've got maybe 45 minutes to nail it. Medium difficulty, 67% acceptance rate, but that's misleading when you haven't seen the pattern before. Directi and Media.net both ask this one. The trap is obvious: greedy doesn't work, and a naive simulation will TLE. This is exactly the problem where you either see the trick or you spiral. If you hit it live and blank, StealthCoder surfaces a working solution invisible to the proctor while you stay calm.
Companies that ask "Minimum Cost to Buy Apples"
Minimum Cost to Buy Apples is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made for the engineer who has done the work but might still blank with a webcam pointed at him.
Get StealthCoderThe trick is recognizing this as a shortest-path problem dressed up as an optimization puzzle. You're not just picking the cheapest apple stand; you're finding the minimum cost route through a state space where each decision creates new options. Most candidates try greedy (always pick the cheapest available) and watch their solution fail on the second test case. The real solution uses a heap to explore states in cost order, letting you prune impossible paths early. Array iteration, graph edges, heap ordering, and relaxation logic all collide here. This combines Dijkstra's essence with careful state representation. When you're under time pressure and the greedy approach crumbles, you'll wish you had a working reference. That's where StealthCoder enters: you paste the problem, it hands you the heap-based blueprint, and you adapt it in 90 seconds instead of 20 minutes of debugging.
Pattern tags
You know the problem.
Make sure you actually pass it.
Minimum Cost to Buy Apples recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made for the engineer who has done the work but might still blank with a webcam pointed at him. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Minimum Cost to Buy Apples interview FAQ
Is this really Medium, or is it harder?+
The 67% acceptance rate is fair. Greedy fails fast, forcing you to think graph. If you recognize the shortest-path structure up front, you code it cleanly. If you don't, you're rewriting after test 2. Medium complexity, high pattern sensitivity.
What's the gotcha that kills most submissions?+
Assuming you can process apples in order or always pick the cheapest option. Both fail when future choices are constrained by past decisions. You need to explore the state space systematically, not assume a linear greedy path works.
How does Heap (Priority Queue) fit in?+
A heap lets you always process the lowest-cost state next, just like Dijkstra. You explore states in order of cost, updating neighbors as you go. Without it, you're doing brute-force or BFS, and both TLE on larger inputs.
Is this question still asked at Directi and Media.net?+
Yes, both companies have reported this problem. It's a solid medium-tier screening question that separates candidates who know graph patterns from those who don't. Shows up in their online assessments regularly.
How much time should I budget if I see this live?+
If you know the heap-shortest-path pattern: 25-30 minutes to code, test, and submit. If you don't: you'll spend 40+ minutes debugging a greedy attempt. This is why a working reference during the live OA is a safety net.
Want the actual problem statement? View "Minimum Cost to Buy Apples" on LeetCode →