Capacity To Ship Packages Within D Days
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Capacity 14 fails Example 1 but capacity 15 works, and that one-step cliff is the whole problem. This is the Amazon shipping-capacity question reported in September 2026, and it's binary search on the answer, not on an array. Packages ship in the given order, so you can't rearrange anything to cheat the load. If the OA invite is sitting in your inbox, learn the feasibility check and the search bounds tonight. StealthCoder is there as a safety net on the live OA if your mind goes blank on the setup, but the pattern is short enough to own.
The problem
A conveyor belt has packages that must be shipped from one port to another within days days. The i-th package has weight weights[i]. Packages are loaded in the given order: you may not rearrange them. Each day, you load the conveyor with packages whose total weight does not exceed the ship's capacity, then ship that day's load. Return the least ship capacity that can move every package within days days. Function shipWithinDays(weights: int[], days: int) → int Examples Example 1 weights = [1,2,3,4,5,6,7,8,9,10] days = 5 return = 15 Capacity 15 ships as [1,2,3,4,5], [6,7], [8], [9], and [10]. Capacity 14 needs more than 5 days. Example 2 weights = [3,2,2,4,1,4] days = 3 return = 6 Capacity 6 ships as [3,2], [2,4], and [1,4]. Constraints 1 <= weights.length <= 5 * 10^4. 1 <= weights[i] <= 500. 1 <= days <= weights.length.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: the answer lives between max(weights) and sum(weights). Any capacity below the heaviest package can't ship it. Any capacity at the total ships everything in one day. Feasibility is monotonic, so if capacity C works, every larger value works too. Binary search that range. For each candidate, greedily simulate: add packages to the current day until the next one would overflow, then start a new day and count. If the count is within days, move the upper bound down. Otherwise move the lower bound up. Common pitfalls: starting the low bound at 1 or 0, forgetting the day counter starts at 1, and resetting the running load to 0 instead of the current weight on overflow. Complexity is O(n log(sum)), which is fine for 5*10^4 packages. If you freeze on the live OA, StealthCoder can hand you this skeleton as a hedge.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Capacity To Ship Packages Within D Days 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. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as capacity to ship packages within d days. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Capacity To Ship Packages Within D Days FAQ
What's the trick in Capacity To Ship Packages Within D Days?+
Binary search on the capacity, not on the array. The lower bound is the heaviest single package and the upper bound is the total weight. For each midpoint, greedily count how many days the in-order loading needs and compare it to days.
Why can't I just divide total weight by days?+
Packages must ship in the given order and each day's load can't exceed capacity. Splits are forced by order, so the average gives only a lower bound. Example 1 has total 55 over 5 days, which is 11, but the real answer is 15.
How hard is this really for an Amazon OA?+
Medium difficulty. The code is short, around 20 lines. The hard part is spotting that the answer is searchable because feasibility is monotonic. Once you see that, it's a template: bounds, check function, shrink.
What are the common off-by-one bugs?+
Starting days at 0 instead of 1, using low = 1 instead of max(weights), and looping with low <= high while also setting high = mid. Use low < high with high = mid on success and low = mid + 1 on failure, and return low.
How do I prepare in 48 hours?+
Write the feasibility function from memory twice, then the binary search wrapper. Test on both examples, expecting 15 and 6. Then try the sibling problems with the same shape, like splitting an array into k subarrays with minimum largest sum.