Get Min Cost
Reported by candidates from Snowflake's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Snowflake's 'Get Min Cost' problem (January 2024) is a greedy optimization question that catches candidates off guard because the obvious solution isn't always the right one. You're given a set of costs and need to minimize some total, but the twist is figuring out which greedy choice actually works. This is where most people second-guess themselves and burn time. StealthCoder reads the full problem and gives you the greedy invariant to follow when you're live.
Pattern and pitfall
The core pattern here is greedy selection: at each step, you make the locally optimal choice and hope it leads to a global optimum. The trap is that not every greedy approach works. You need to identify what you're actually minimizing (total cost, number of operations, time spent) and then prove to yourself that taking the best immediate option doesn't block a better path later. Common pitfall: sorting by one metric when you should sort by another, or forgetting that ties matter. The algorithm is usually O(n log n) due to sorting. When you're in the OA and the greedy logic isn't clicking, StealthCoder shows you the exact ordering or selection rule that works, so you can code confidently instead of guessing.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Get Min Cost 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 StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Snowflake's OA.
Snowflake 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.
Get Min Cost FAQ
Is this a dynamic programming problem or just greedy?+
It's pure greedy. DP would be overkill here. The trick is proving that the greedy choice is safe, not backtracking or storing sub-solutions. If you're thinking DP, you're overcomplicating it. Identify the cost metric and sort once.
What's the most common mistake on this problem?+
Sorting by the wrong attribute. Candidates often sort by raw cost when they should sort by cost-per-unit or by some derived metric. Read the problem statement twice for what 'min cost' actually means in context. It's rarely just the sum of the smallest numbers.
How much time should I spend on logic vs coding?+
Spend 5-7 minutes proving the greedy invariant on paper or in your head. Once you're confident the approach is sound, coding takes 3-5 minutes. Jumping straight to code without validating the greedy choice is how you waste 20 minutes in a dead end.
Do I need to handle edge cases like zero costs or single items?+
Almost certainly yes. Check if all costs are the same, if there's only one item, or if costs are zero. These edge cases often reveal whether your greedy logic is actually correct. Test your invariant against them before submitting.
Is this problem still being asked by Snowflake in 2024?+
Yes. Greedy optimization is a staple of Snowflake's OAs because it tests algorithmic thinking without requiring obscure tricks. Expect variants on this theme across multiple rounds if you advance.