FastPrepCapacity to Ship Packages Within Days
Problems/Capacity to Ship Packages Within Days

Capacity to Ship Packages Within Days

Microsoft logoMicrosoft● MediumFULLTIMEINTERNOAONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This practice problem matches about 99% of the reported task-allocation question. Consecutive shipping days represent contiguous task groups, with the same workload bounds and objective.

Packages must be shipped in the order given by weights. Each day, load a consecutive part from the beginning of the remaining packages without exceeding the ship's capacity.

Return the smallest positive capacity that ships every package within days days. Some days may be unused, including when there are more days than packages. The required capacity may exceed a 32-bit integer.

This is also the ordered task-allocation problem: package weights represent task durations, days represent available resources, and each resource receives one contiguous group of tasks. The capacity is the maximum total duration assigned to any resource.

Function

shipWithinDays(weights: int[], days: int) → long

Examples

Example 1

weights = [1,2,3,4,5,6,7,8,9,10]days = 5return = 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 = 3return = 6

The loads can be [3,2], [2,4], and [1,4].

Example 3

weights = [1,2,3,1,1]days = 4return = 3

Capacity 3 is enough and no capacity below the heaviest package can work.

Example 4

weights = [4,3,2,2,2,6]days = 3return = 7

The groups [4,3], [2,2,2], and [6] have loads 7, 6, 6. Capacity 6 would need four groups: [4], [3,2], [2,2], and [6]. The minimum is 7.

Example 5

weights = [9,2,4,4,5]days = 2return = 13

Split into [9,2] and [4,4,5], with loads 11 and 13. At capacity 12, the greedy groups are [9,2], [4,4], and [5], so two days are insufficient. The minimum is 13.

Constraints

  • 1 <= weights.length <= 10^5.
  • 1 <= weights[i] <= 10^9.
  • 1 <= days <= 10^5.

More Microsoft Onsite Interview questions

  • Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Minimum Daily Printing LimitAgoda · ONSITE INTERVIEWAgoda interview questions
  • Minimize the Longest Hike Between Rest StopsPinterest · ONSITE INTERVIEWPinterest interview questions
  • Rock JumpingIMC Trading · OAIMC Trading interview questions
  • Minimum Robot and Human Fulfillment TimeAmazon · OA
  • Minimize Maximum Pilot WorkloadSpotnana · ONSITE INTERVIEWSpotnana interview questions
  • Minimize Maximum Group DifferenceDRW · OADRW interview questions
  • Array NullificationQRT · OA
  • Minimum-Cost Solar Rooftop AllocationDeloitte · OADeloitte interview questions
  • Three-Part Partition with Minimum Largest RangeLSEG · OALSEG interview questions
  • K-Means ClusteringAtlassian · OAAtlassian interview questions

Interview reports that mention this question

  • Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public long shipWithinDays(int[] weights, int days) {
        // Write your code here.
    }
}
Checking account…