HARDasked at 4 companies

Put Marbles in Bags

A hard-tier problem at 72% community acceptance, tagged with Array, Greedy, Sorting. Reported in interviews at DE Shaw and 3 others.

Founder's read

Put Marbles in Bags is a hard problem that's shown up at DE Shaw, Flipkart, TikTok, and Uber. On the surface it looks like a simple distribution problem, but the greedy insight isn't obvious and the wrong approach will TLE or give wrong answers. The 72% acceptance rate tells you most people who attempt it get it right, which means the trick is learnable but easy to miss cold in an assessment. If this problem hits your live OA and you blank on the greedy pattern, StealthCoder solves it in seconds, invisible to the proctor.

Companies asking
4
Difficulty
HARD
Acceptance
72%

Companies that ask "Put Marbles in Bags"

If this hits your live OA

Put Marbles in Bags 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 by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE.

Get StealthCoder
What this means

The problem forces you to think about optimal distribution under constraints. The naive approach (distribute evenly or sequentially) fails because you need to minimize some cost function across bags. The winning move is recognizing that sorting the input and using a greedy strategy (often paired with a heap or priority queue) produces the optimal answer. Most candidates miss that you're not just placing marbles, you're minimizing the maximum bag weight or similar. Array, Sorting, and Heap work together here: you sort the input, then use a min-heap to always place the next marble in the lightest bag. Common pitfall is forgetting to re-heapify after each insertion, or not recognizing that greedy placement by heap order actually yields the global optimum. StealthCoder is the hedge if you recognize it's a heap problem but can't sketch the full solution fast enough.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Put Marbles in Bags recycles across companies for a reason. It's hard-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 by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Put Marbles in Bags interview FAQ

Is this really a hard problem or does it just look hard?+

Both. The concept is hard because the greedy insight isn't intuitive. Once you spot that you need a heap and sorted order, implementation is straightforward. The 72% acceptance rate suggests experienced candidates see the pattern quickly, but cold you can easily go down the wrong path and burn time.

What's the most common wrong approach?+

Trying to distribute marbles in order without sorting first, or assuming a round-robin or even split works. You'll get wrong answers or TLE because you're not minimizing the actual objective. Sorting plus heap is the unlock.

How does this relate to Heap and Greedy together?+

Greedy tells you the strategy (always add to the lightest bag). Heap lets you find 'lightest' in O(log n) per insertion instead of O(n). Combined, you get optimal time complexity. Sorting first ensures greedy correctness.

Does this problem still show up at these companies?+

It's on the books at DE Shaw, Flipkart, TikTok, and Uber. That's a real signal. Companies that care about algorithmic depth and optimization tend to repeat it because it tests multiple skills at once.

What should I drill before the OA if I haven't seen this?+

Know heap insertion and re-heapify cold. Practice problems where you sort first, then greedily process. Understand when a min-heap beats a linear scan. If you're comfortable with those three things, the pattern should surface during the OA.

Want the actual problem statement? View "Put Marbles in Bags" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.