Question: Debug the Code class Solution { public: int shipwithinDays (vectorcint>& weights, int days) { int ma e; int right=e; for(auto x: weights) ma=max (ma, x);

 Debug the Codeclass Solution { public: int shipwithinDays (vectorcint>& weights, int days) { int

class Solution { public: int shipwithinDays (vectorcint>& weights, int days) { int ma e; int right=e; for(auto x: weights) ma=max (ma, x); right+x; int left-ma; while(left mid) need++; curse; curt=x; if(need>days) left-mid+1; else right=mid; return left; Debug this code. It is not working on base testcase A conveyor belt has packages that must be shipped from one port to another within days days. The ith package on the conveyor belt has a weight of weights[il. Each day, we load the ship with packages on the conveyor belt (in the order given by weights ). We may not load more weight than the maximum weight capacity of the ship. Return the least weight capacity of the ship that will result in all the packages on the conveyor belt being shipped within days days. Example 1: Inputt weights - (1,2,3,4,5,5,7,8,9,10), days - 5 Output as Explanation A ship capacity of 15 is the ninimun to ship all the packages in s days 1ike this: 1st day: 1, 2, 3, 4,S 2nd dayI 6, 7 3rd daya 4th day:9 Sth day: 10 Note that the cargo ust be shipped in the order given, so

Step by Step Solution

3.48 Rating (158 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Mistake Line number 15 is wrong mid should calculate as midleftrightleft2 because right ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Algorithms Questions!