135. Allocate Books (Binary Search + Greedy)

HardArrayArray

Given pages of n books (in order) and m students, allocate contiguous books so each student gets at least one book and the maximum pages assigned to any student is minimized. Return that minimum; return -1 if m>n. Input: '[books], m'.

Input: '[books], m'.

Output: Integer — minimized max pages, or -1.

Examples

Example 1
Input: [12,34,67,90], 2
Output: 113
Explanation: [12,34,67] and [90].
Example 2
Input: [10,20,30,40], 2
Output: 60
Explanation: [10,20,30] and [40].
Example 3
Input: [1,2,3,4], 1
Output: 10
Explanation: All to one student.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →