486. Allocate Books (Minimize Maximum Pages)

MediumBinary SearchBinary Search on AnswerArray

Given the page counts of books arranged in order and a number of students, allocate contiguous books to students so each gets at least one book and the maximum pages assigned to any student is minimized. Return that minimized maximum, or -1 if there are more students than books. Input: '[books], students'.

Input: '[books], students'.

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

Examples

Example 1
Input: [12,34,67,90], 2
Output: 113
Explanation: Split as [12,34,67] and [90].
Example 2
Input: [15,17,20], 2
Output: 32
Explanation: [15,17] and [20].
Example 3
Input: [10,20,30,40], 1
Output: 100
Explanation: One student takes all.

Constraints

Asked by

AmazonMicrosoftGoogleAdobeFlipkart
Solve this problem in the editor →