MEDIUMasked at 1 company

Filling Bookcase Shelves

A medium-tier problem at 69% community acceptance, tagged with Array, Dynamic Programming. Reported in interviews at Flipkart and 0 others.

Founder's read

You're staring at a bookcase layout problem and the greedy approach feels right until you hit a case where it wastes space. This is a classic dynamic programming trap masquerading as a packing problem. Flipkart has asked it. The acceptance rate sits at 68.6%, which means a third of people either overthink it or miss the state transitions entirely. The problem forces you to choose between shelves strategically, not just fill them left-to-right. If you blank on the DP recurrence during the live OA, StealthCoder runs invisibly and surfaces the working solution in seconds.

Companies asking
1
Difficulty
MEDIUM
Acceptance
69%

Companies that ask "Filling Bookcase Shelves"

If this hits your live OA

Filling Bookcase Shelves 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 trick is recognizing that you can't greedily pack books onto shelves without considering future books. Your state needs to track which book you're placing and minimize the total cost across all shelves. Most candidates build the wrong recurrence or forget to precompute the cost of placing a contiguous range of books on one shelf. The problem lives at the intersection of Array and Dynamic Programming because you're partitioning an array into contiguous groups, each with a cost function. The DP state is typically dp[i] equals the minimum cost to arrange the first i books, and the transition iterates back through valid shelf configs. Where people fail is either computing shelf costs wrong (width calculation, height logic) or not seeing that each shelf choice locks in a fixed cost. StealthCoder is the hedge when the pattern doesn't click and you're burned for time.

Pattern tags

The honest play

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

Filling Bookcase Shelves 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 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.

Filling Bookcase Shelves interview FAQ

Is this really just greedy packing?+

No. Greedy fails because placing books left-to-right without looking ahead wastes shelf height. DP solves it by trying all valid partitions and picking the minimum-cost arrangement. The state tracks how many books you've placed, the transition tries all possible shelf boundaries.

What's the acceptance rate really saying?+

At 68.6%, about one in three candidates doesn't get it right. That's not random guessing. Most likely they nail the greedy intuition or the basic DP setup but fail on the cost calculation or state transition logic. It's a pattern-matching miss, not a fundamental algorithmic gap.

Which topic bites most people?+

The Array aspect. Candidates focus on DP but forget they need to precompute or efficiently calculate the width and cost of placing books[i] through books[j] on one shelf. Missing this means either slow O(n4) solutions or wrong costs.

Does Flipkart ask this often?+

It's in their reported problem list, so it appears in rotations. Not a guarantee you'll hit it, but if you're interviewing there, this is a real vector. The single company tag and medium difficulty suggest it's a reliable screening ask.

How do I avoid the state transition trap?+

Write out the recurrence on paper before coding. dp[i] should equal the min cost to place books 0 to i-1. For each j from 0 to i-1, the cost of placing books[j] to books[i-1] on one shelf plus dp[j]. Test with a small example to verify width and height logic before scaling.

Want the actual problem statement? View "Filling Bookcase Shelves" 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.