Reported October 2026
Microsoftbinary search

Capacity to Ship Packages Within Days

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

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

The packages ship in the order given, and no single package can be split. That one detail in the Microsoft problem reported in October 2026 tells you what the OA wants: binary search on the answer, not on the array. If you've got the invite and 48 hours, learn the shape of this one. You guess a capacity, simulate the days greedily, and shrink the range. It's short once you see it. If you blank mid-assessment, StealthCoder runs invisibly on your desktop and gives you the solution live, so one lost idea doesn't sink the whole OA.

The problem

Packages must be shipped in the order given by weights. Each day, load a consecutive prefix of the remaining packages without exceeding the ship's capacity.
Return the smallest positive capacity that ships 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 the ordered packages in five days, while any smaller capacity needs more days.
Example 2
weights = [3,2,2,4,1,4]
days = 3
return = 6
The loads can be [3,2], [2,4], and [1,4].
Example 3
weights = [1,2,3,1,1]
days = 4
return = 3
Capacity 3 is enough and no capacity below the heaviest package can work.

Constraints
1 <= weights.length <= 50000.
1 <= weights[i] <= 500.
1 <= days <= weights.length.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that feasibility is monotonic. If capacity C works, any larger capacity works too. So binary search the capacity. The lower bound is max(weights), since the heaviest package must fit on some day. The upper bound is sum(weights), which ships everything in one day. For each mid, run a greedy pass: add weights to the current day, and when the next one overflows, start a new day and count it. If days used is at most the limit, try smaller. Otherwise go bigger. Complexity is O(n log(sum)), fine for 50000 packages. The common pitfall is starting the low bound at 1 or 0, which makes the greedy check break or return a wrong answer. Another is an off-by-one in day counting, since you start at day 1. StealthCoder is the hedge if the binary-search-on-answer idea won't come to you during the live OA.

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 Capacity to Ship Packages Within 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. 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 capacity to ship packages within d days. If you have time before the OA, drill that.

⏵ The honest play

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

Microsoft 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.

Capacity to Ship Packages Within Days FAQ

What's the trick in Capacity to Ship Packages Within Days?+

Binary search on the capacity, not on the array. Capacity is monotonic: if it works, bigger works. Search between the heaviest single package and the total weight, and use a greedy simulation to check whether a given capacity fits within the allowed days.

How hard is this one really?+

Medium. The code is about 20 lines. The hard part is spotting that you can binary search an answer range. Once you've seen that pattern, the greedy check is straightforward, and the whole thing runs in O(n log sum).

What should the binary search bounds be?+

Low is the maximum weight, because every package must fit on a single day. High is the sum of all weights, which ships everything in one day. Starting low at 1 is the classic bug, since some capacities can't carry the heaviest package.

Can I reorder packages to make it easier?+

No. The statement says packages ship in the given order, and each day takes a consecutive prefix of what's left. That's why a simple greedy count works for the check. Sorting would give wrong answers on examples like [3,2,2,4,1,4].

How do I prepare for this in 48 hours?+

Write the feasibility function first: count days greedily for a given capacity. Then wrap it in a binary search and test on the three examples. Do one or two similar binary-search-on-answer problems after that. Expect the pattern to show up in variants at Microsoft.

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

OA at Microsoft?
Invisible during screen share
Get it