Weight Capacity for Shipment in D Days

You are tasked with managing a shipment company that utilizes conveyor belts to transport packages from one port to another. These packages must be shipped within ‘D’ days.

The package weights are provided in an array called WEIGHTS. Packages are loaded daily onto the conveyor belts in the sequence they appear in the array. The goal is to ensure that the total weight loaded each day does not exceed the ship's maximum weight capacity.

Your task is to determine the minimum weight capacity needed to deliver all packages within ‘D’ days.

Input:

The first input line contains an integer ‘T’, representing the number of test cases. Each test case is described as follows.

For each test case:
The first line contains two integers, ‘N’ and ‘D’. ‘N’ is the size of the array ‘WEIGHTS’, and ‘D’ is the maximum allowable days for shipment.
The second line contains ‘N’ integers detailing the elements of the array ‘WEIGHTS’.

Output:

For each test case, return the minimum weight capacity required to ship all the packages in ‘D’ days.

Example:

Input:
T = 2
N = 5, D = 3
WEIGHTS = [10, 20, 30, 40, 50]
N = 4, D = 2
WEIGHTS = [1, 2, 3, 4]
Output:
Output for first test case: 60
Output for second test case: 5

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 50000
  • 1 <= D <= 50000
  • 1 <= WEIGHTS[i] <= 500
  • Time Limit: 1 second

Note:

You do not need to explicitly output the results, as this will be handled for you. Simply implement the function to compute the results.
AnswerBot
4mo

Calculate minimum weight capacity needed to deliver all packages within 'D' days.

  • Iterate through the array of weights to find the maximum weight

  • Use binary search to find the minimum weight capacity ne...read more

Help your peers!
Select
Add answer anonymously...

Morgan Stanley Software Developer interview questions & answers

A Software Developer was asked 8mo agoQ. Given an integer array nums and an integer k, return the kth largest element in ...read more
A Software Developer was asked 9mo agoQ. Explain the concept of a HashMap.
A Software Developer was asked Q. Why do you want to work at Morgan Stanley?

Popular interview questions of Software Developer

A Software Developer was asked 5mo agoQ1. What is abstraction?
A Software Developer was asked 8mo agoQ2. Given an integer array nums and an integer k, return the kth largest element in ...read more
A Software Developer was asked 9mo agoQ3. Explain the concept of a HashMap.
Morgan Stanley Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits