MEDIUMasked at 10 companies

Capacity To Ship Packages Within D Days

A medium-tier problem at 72% community acceptance, tagged with Array, Binary Search. Reported in interviews at Agoda and 9 others.

Founder's read

You've got a pile of packages and D days to ship them all. The catch: you can only ship packages in order, and your ship has a weight limit. Find the minimum capacity needed. Amazon, Meta, and DoorDash ask this regularly. It looks like a greedy problem until you realize greedy doesn't work. The trick is binary search on the answer space, not the input. Most candidates blank on that pivot and waste 20 minutes on dead ends. If this problem hits your live OA and you freeze on the approach, StealthCoder solves it invisible to the proctor.

Companies asking
10
Difficulty
MEDIUM
Acceptance
72%

Companies that ask "Capacity To Ship Packages Within D Days"

If this hits your live OA

Capacity To Ship Packages Within D Days 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 naive instinct is to greedily pack as many packages as possible each day. That fails because you're constrained by the weight limit and the order requirement simultaneously. The actual solution: binary search on the ship capacity. The low bound is the heaviest single package. The high bound is the sum of all packages. For each candidate capacity, simulate shipping and check if you can finish in D days. If yes, try smaller. If no, try larger. This is a classic binary search on answer pattern. Array and Binary Search are listed topics for a reason. The pitfall is overthinking it as a packing problem when it's really a feasibility check wrapped in binary search. StealthCoder is the hedge for the moment you realize greedy isn't the play and you need to lock in binary search fast.

Pattern tags

The honest play

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

Capacity To Ship Packages Within D Days 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.

Capacity To Ship Packages Within D Days interview FAQ

Is this still asked at big tech?+

Yes, frequently. Amazon, Meta, DoorDash, and Salesforce all report it. It's medium difficulty with a 72% acceptance rate, so it's not a trick question, just a pattern recognition test. If you know binary search on answer space, you're fine.

Why doesn't greedy work?+

Greedy tries to pack as much as possible per day, but that doesn't guarantee the minimum capacity. You need to search for the capacity threshold where shipping in D days becomes feasible. That's a binary search problem, not a packing problem.

What's the main gotcha?+

Confusing this with a load balancing problem. It's not. You can't reorder packages. Once you lock the capacity, simulation is straightforward. The hard part is recognizing that binary search on capacity is the right frame.

How do I know my bounds for binary search?+

Minimum capacity is the weight of the heaviest package. You must be able to ship that alone on some day. Maximum is the sum of all packages. You could ship everything in one day if you had infinite capacity. Search between those bounds.

Do I need to optimize the simulation loop?+

No. The simulation for a given capacity is O(n). Binary search runs O(log(sum)). Total is O(n log(sum)), which is efficient enough. Focus on correctness over micro-optimizations.

Want the actual problem statement? View "Capacity To Ship Packages Within D Days" 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.