please provide code for this question i did’t get this one
Book allocation problem
code will not help much
i will try to explain the problem and tell how to approach
first try this
sample input
1
4 2
12 34 67 90
question is we have to minimize maximum number of pages assigned to a student
There are 2 number of students. Books can be distributed
in following fashion :
- [12] and [34, 67, 90]
Max number of pages is allocated to student
2 with 34 + 67 + 90 = 191 pages - [12, 34] and [67, 90]
Max number of pages is allocated to student
2 with 67 + 90 = 157 pages - [12, 34, 67] and [90]
Max number of pages is allocated to student
1 with 12 + 34 + 67 = 113 pages
Of the 3 cases, Option 3 has the minimum pages = 113.
so 113 is ans
hint : use BinarySearch to solve this problem
approach to solve problem
We fix a value for the number of pages as mid of current minimum and maximum. We initialize minimum and maximum as arr[n-1] 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 how to check current mid is ans or not?
this you try to think first
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.
The doubt was reopened. Is your doubt resolved?
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.