546. Allocate Minimum Number of Pages (Multi-Constraint)

HardBinary SearchBinary Search on AnswerArray

Given page counts of books arranged in order and a number of students, allocate contiguous books to students so each student 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: [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: All to one student.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →