Book Allocation Problem

Sample test case is passing, but others are not. Please tell what’s wrong in my code.

I have edited your code a little bit, there are few changes that I have made in your code :

  1. In your bool isValid function I have added two conditions as :
    if(pages[i]>mid)
    {
    return false;
    }
    and this condition as :
    else
    {
    currentPages=currentPages+pages[i];
    }
  2. In line no 35, s=0, instead of pages[n-1]
  3. In line no 42 as while(s<=e)

Pls try to submit this code now, I have made the changes…

In line 35, I think if we initialise s=pages[n-1] i.e. the max no of of pages a book has will also work fine as in any case min of max pages assigned to a student will not be less than max pages a book contain. The same thing was told by prateek bhaiya in the video.

Also could you please explain the changes you made in isValid() function with an example. i think that pages[i]>mid this condition will never be reached in my code as i have not started s with 0.

Ma’am could you please reply??

Pls go through the video again, I have checked it again,( at roughly time of 17:24, ) prateek bhaiya has told that minimum value assigned to s will be 0 and not pages[n-1] , and the thts why I have included the condition in isValid function as if(pages[i]>mid), If you still face any issue you can ask me…

Ma’am each student will read at least one book. And the book containing max no of pages, i.e.pages[n-1] will definitely be assigned to one of the students. So, ‘s’ in any case cannot be less than pages[n-1]. So , I think if s initially points to pages[n-1] then that will not create any problem. In the video, (roughly at time 18:35) same thing has been told.