Why this is wrong solution in testy cases
problem is simple but you make it complex
there is no need to make cum_sum[1000] array also
no need to make this recursive function bool CanAllRead(int pages , int rem_stu , int idx)
you can do this with simple while loop
The idea is to use[Binary Search. We fix a value for the number of pages as mid of current minimum and maximum. We initialize minimum and maximum as 0 and sum-of-all-pages respectively. If a current mid can be a solution, then we search on the lower half, else we search in higher half.
Now the question arises, how to check if a mid value is feasible or not? Basically, we need to check if we can assign pages to all students in a way that the maximum number doesn’t exceed current value. To do this, we sequentially assign pages to every student while the current number of assigned pages doesn’t exceed the value. In this process, if the number of students becomes more than m, then the solution is not feasible. Else feasible.
try to solve question in simplest way
making it complex will not benefit in any way but definetly waste your time and you may loose interest
you can take help from this video
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.