Reported February 2024
Akunagreedy

Min Cost (Akuna Shang Hai)

Reported by candidates from Akuna's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Akuna OA. Under 2s to a working solution.
Founder's read

Akuna's Min Cost problem hit the February OAs, and it's a greedy trap. You see a cost minimization prompt and your brain goes straight to dynamic programming or exhaustive search. Wrong. The actual trick is recognizing that a greedy choice at each step gives you the optimal answer without backtracking. StealthCoder will show you the pattern instantly if you blank on which choice is always safe to make first. Know the greedy invariant before you sit down, and you avoid the sunk-cost fallacy that kills most candidates on this one.

Pattern and pitfall

Min Cost problems in this mold almost always hinge on sorting or prioritizing by a specific attribute, then making the locally optimal choice every time. The greedy insight is that you never need to revisit earlier decisions. Common pitfall: candidates build a solution, hit a test case, then second-guess and rewrite to DP or brute force, burning 10 minutes and confidence. The hedge is to nail the greedy proof in your head first. Which metric (lowest cost, highest count, earliest deadline) makes the next step obvious. Once you lock that, code is fast and clean. StealthCoder runs the logic in parallel if you stall, but the real win is walking in knowing greedy works and why.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Min Cost (Akuna Shang Hai) cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Akuna's OA.

Akuna reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Min Cost (Akuna Shang Hai) FAQ

Is this a sorting problem or a priority queue problem?+

Almost always sorting. Greedy problems at Akuna typically reward you for processing elements in a specific order, then iterating once. Use a heap only if you're inserting and removing dynamically. Start with sort.

What's the common failure case on Min Cost?+

Assuming you need to explore multiple paths. Candidates spend time on backtracking or memoization when a single sorted pass works. Test your greedy choice on the provided examples. If it works, trust it.

How do I know which attribute to sort by?+

Read the cost function carefully. What happens if you pick the smallest value first? The largest? The earliest? Run through an example by hand and see which choice prevents future regret. That's your greedy key.

Should I code defensively for edge cases first?+

No. Get the greedy logic correct on the happy path, then add guards. Empty input, single element, all identical costs. Check those after your main loop is solid.

Can I brute force this if greedy fails?+

You can try, but Akuna's test cases are sized to punish brute force. If a greedy proof eludes you in 5 minutes, restart. Don't code a slow solution hoping it passes.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Akuna.

OA at Akuna?
Invisible during screen share
Get it