Binary Search Searching the answer
250. Book Allocation
A shelf holds books in a fixed order, and book i has pages[i] pages. Share the books out among
students students. Each student gets a run of books that stand next to each other on the shelf, every
student gets at least one book, and every book goes to exactly one student. A book cannot be split.
The load of an allocation is the largest number of pages any one student reads. Return the smallest load
any allocation can have. If there are more students than books, no allocation is possible, so return -1.
Example 1
Input: pages = [40, 10, 25, 35, 20, 30], students = 3
60Explanation: Give [40, 10], [25, 35] and [20, 30] to the three students. They read 50, 60 and 50 pages, so the
load is 60. Every allocation to three students has someone reading more than 59 pages.
Example 2
Input: pages = [50, 20], students = 3
-1Explanation: Three students need at least three books, and the shelf has only two.
Example 3
Input: pages = [1000000000, 1000000000, 1000000000]
students = 2
2000000000Explanation: One of the two students has to read two of the books.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
1 ≤ pages.length ≤ 1051 ≤ pages[i] ≤ 1091 ≤ students ≤ 105
Clarifying questions
What you would ask an interviewer before writing any code.