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.
Be the first one to answer
Add answer anonymously...
Top Morgan Stanley Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Morgan Stanley Software Developer
>
Morgan Stanley Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app