Reported December 2024
Snowflakeheap priority queue

Remove Stones to Minimize the Total

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

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

Snowflake hit you with a heap problem in December 2024, and the title is a tell: Remove Stones to Minimize the Total. You've got a pile of stones with weights, and you're removing them one at a time. Each time you remove a stone, the remaining stones get lighter (usually by half, rounded). The trick is figuring out which stone to remove first to minimize the total weight removed. This is a pure greedy heap play, and StealthCoder can feed you the pattern if you blank on the heap construction during the live OA.

Pattern and pitfall

The core insight is that you want to remove the heaviest stones first. By removing a large stone early, you reduce its effective weight in future rounds because other stones shrink after each removal. Use a max heap (or negate values in a min heap) to always grab the heaviest remaining stone, remove it, and re-insert the reduced version. Python's heapq is a min heap by default, so push negative values. The trap candidates fall into is trying to brute-force or greedily pick without tracking the shrinking values. The algorithm runs in O(n log n) or better depending on the total weight. StealthCoder handles the heap boilerplate so you focus on the removal loop logic when you're live.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Remove Stones to Minimize the Total 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 for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as last stone weight. If you have time before the OA, drill that.

⏵ The honest play

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

Snowflake reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Remove Stones to Minimize the Total FAQ

Do I need to simulate every single removal?+

Yes. You can't calculate the final answer without walking through each removal step. Each step depends on the previous one because the weights change. That's why the heap is essential, not just sorting once.

What happens after I remove a stone?+

The stone gets lighter (usually divided by 2, rounded down) and goes back into the heap. You continue until the heap is empty or a stopping condition is met. The problem statement will define the exact shrink rule.

Is this a well-known LeetCode pattern?+

It's similar to problems like 'Last Stone Weight' but with a twist on the shrinking mechanic. The heap greedy approach is standard, but Snowflake's variant changes how stones shrink and what you're minimizing.

How long should this take to code?+

If you know heaps, 10-15 minutes. The loop is straightforward once you build the heap. Most time goes to debugging off-by-one errors in the shrink rule or heap operations.

Can I solve this with sorting instead of a heap?+

No. Sorting once won't work because the stone weights change after each removal. You need a dynamic data structure that lets you always access and re-insert the max efficiently.

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

OA at Snowflake?
Invisible during screen share
Get it