Debug the Code class Solution { public: int shipwithinDays (vectorcint>& weights, int days) { int ma e;
Fantastic news! We've located the answer you've been seeking!
Question:
Debug the Code
Transcribed Image Text:
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 leftma; while(left<right) int mid=left+(leftright)/2; int curse, need=1; for (auto x:weights) if((cur+x)>mid) need++; curse; curt=x; if(need>days) leftmid+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
Expert Answer:
Answer rating: 100% (QA)
Mistake Line number 15 is wrong mid should calculate as mid left right left 2 because right View the full answer
Posted Date:
Students also viewed these algorithms questions

Explain how to debug code by commenting it out.

My code is not working, can you check and edit the to do regions? EmployeeTester.java /**A class to demothe employee classes.*/ public class EmployeeTester { public static void main(String[] args) {...

I need an HTML Code for my website page When somebody searches Google and ask "what is my IP" My website page shows up in google search results and when person clicks the link to find his/her IP, it...

Knowing that two equal caps have been removed from a 10in.diameter wooden sphere, determine the total surface area of the remaining portion. 4 in 10 in.

For the model of Question 3, suppose that the Home government convinces the foreign government to impose a VER on the F firm. (a) Suppose that the VER restricts F's exports to be no more than its...

J.P. Morgan Asset Management publishes information about financial investments. Over the past 10 years, the expected return for the S&P 500 was 5.04% with a standard deviation of 19.45% and the...

Repeat Problem 1022 for the following CISC instructions. Borrow B is defined as the complement of the carry out, C. Problem 1022 Repeat Problem 1021 for the following CISC instructions that are...

Rita Gonzales won the $41 million lottery. She is to receive $1.5 million a year for the next 19 years plus an additional lump sum payment of $12.5 million after 19 years. The discount rate is 14...

What is the efficiency class of each of the following functions? (a) 3x + 1 (b) 32209 (c) 2x + 30x100 (d) 3 log (x + 1) + 10 (e) 30x + 2* (f) 200x + 3x!

There is a database that contains a website's traffic data over a period of 30 days. The first table contains users' information including the user type (user, crawler, admin). The second table...

Access Control Strategy Report Your recent endeavors to convince upper management at LOTR Experience not to cut the security budget have paid off. After hearing your rationale, management agreed to...

Solve Problems 2124 using elimination by addition. 2x  3y = 8 5x + 3y = 1

How is it possible for a nucleus to eject an electron when it contains no electrons?

Explain why the process of nuclear fusion will not release energy if the atoms fused are larger than 56 Fe.

What kind of nucleus would be likely to eject two neutrons and two protons?

A family needs $5,000 to finance an addition to their home. If the local credit union is willing to lend them the money at 0.8% per month on the unpaid balance, and asks for the money to be paid back...

The permanent mode of deformation of a material known as_____________ 8a) Elasticity 8b) Plasticity 8c) Slip deformation 8d) Twinning deformation and WHY?

Suppose that a flow network G = (V, E) violates the assumption that the network contains a path s t for all vertices V. Let u be a vertex for which there is no path s u t. Show that there must...

How far from the lens must the film in a camera be, if the lens has a 35.0 mm focal length and is being used to photograph a flower 75.0 cm away? Explicitly show how you follow the steps in the...

A certain slide projector has a 100 mm focal length lens. (a) How far away is the screen, if a slide is placed 103 mm from the lens and produces a sharp image? (b) If the slide is 24.0 by 36.0 mm,...

A doctor examines a mole with a 15.0 cm focal length magnifying glass held 13.5 cm from the mole (a) Where is the image? (b) What is its magnification? (c) How big is the image of a 5.00 mm diameter...
Question Categories