Book allocation - doubt in understanding the solution

in is valid function , why we are returning true even if the number of students is less than students .the only case for true should be when we have alloted books to all the students

@raashi31 In this problem, we have to minimize the maximum number of pages each student has to read.
Note that whenever there are such optimization problem where you have to maximize/minimize and the span of final answers form a monotonic function, Binary Search approach can be applied.
Consider sample case: where there are 4 books and 2 student
Pages in each book: 10 20 30 40 Here answer is 60.(1 student allotted 10+20+30 pages and other 40 pages)
Here the span of answers will be from 0 to 10+20+30+40=100 as a student can read a maximum of 100 pages.You answer will lie in this span and you have to optimize it. We say that the span of answers form a monotonic function because answer<60 is not possible(for which isValid function will return false) and answer>60 is always possible(for which isValid function will return true).Least among all true values(ie.60) is the answer for which we apply binary search:
So as per your query, we return true even if the number of students is less as we have to optimize and find the least among all true or the lower bound for true. So,
IsValid function returns false only when the number of students computed in it is greater than the given number of students.
IsValid function returns true when the number of students computed <=the given number of students

Hope this help.

@pratyush63
thanks for the explanation.

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.