Code Stuck in infinite loop

Please identify my problem instead of providing sloution
code - https://ide.codingblocks.com/s/231750

Hey Anubhav, don’t decrease i in line 13, also isPossible needs to be implemented properly, think of a case when arr[i]>pages!

I have tried to dry run my code and i think we need to do i-- as Humne agar zayada pages padh liye to hum piche gaye array mai fresh start kra 0 se or pdhna shuru kra
and i dont get it what do you mean by arr[i]>pages

You don’t have to go back for this, you can start allotting from current index to new student(as condition was valid on previous index). Think if arr[i]>pages, then you go back and start fresh, now whenever you again come back adding arr[i] always makes pages_read>pages, so again go back and this thing goes on, therefore you end up in infinite loop.

please check it again i tried to modify my code but still not working

See my implementation:

okay i get to know how your code is working.
so now i understand what do you mean by arr[i]>pages! but for that I have already put my start = arrr[books -1 ] so that it will never occur.
could you please help me to find mistake in my code

put start = max(books[i]) as it is not necessary that book[n-1] is maximum

it is a sorted array so it should me necessary that n-1 is maximum

No array is not sorted and you also dont have to sort it as order of elements can change answer

we are applying binary search if it is not sorted there is no way we can impilment the binary search and my code is exact same as sir coded in the video. sir also used start= arr[books-1]

Dear Anubhav, using binary search we look for optimal answer and then validate it on pages[ ] , if for some value answer is possible then we look for further smaller values.
Think it this way that we check whether it is possible to assign maximum of 1 page to every student, if yes we got the answer else we check for 2,then for 3,4,5,6… uptil we get a valid answer, this process is simplified by using binary search. If you still can’t get it I would recommend you go through video again

ok i get it that pages array is not necessary to be in sorted order but still my code is not working for sorted array in put even i want to know what is wrong in my code if array is starting from arr[n-1] thenwe dont have to check for if(a[i]>t) and i have tried to like compared my code with sir code it is like completly same instead of variables name please check my code and comment out my mistakes


see your code

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.