Split the Reading Load
Books in a fixed order have pages[i] pages. Assign them to m readers so that each reader gets a contiguous block of at least one book. Minimise the largest number of pages any reader gets, and return it. Return -1 if there are fewer books than readers.
Requirements
- Binary search the answer between and .
Constraints
- ,
Examples
EXAMPLE WALKTHROUGHclassic
A guided view of the published example, not a trace of your code.
INPUT
[[12,34,67,90],2]TASKsplit_reading_load()
EXPECTED OUTPUT
113Start with the input values shown in this example.
Example 1 of 3
Input: pages = [12,34,67,90], m = 2
Output: 113
Explanation: classic
Input: pages = [10,20,30,40], m = 2
Output: 60
Explanation: even split
Input: pages = [5,5], m = 3
Output: -1
Explanation: not enough books
Hint 1
For a limit L, count how many readers are needed if each takes books greedily until adding one more would exceed L.
Hint 2
Find the smallest L that needs at most m readers.