Given an array pages where pages[i] represents the number of pages in the ith book, and an integer m representing the number of students, allocate the books such that each student gets at least one book and each book is assigned to exactly one student. Books must be allocated in contiguous order. The task is to minimize the maximum number of pages assigned to any student. Return the minimum possible value of the maximum pages assigned.
Example 1
Input: pages = [12,34,67,90], m = 2
Output: 113
Explanation: The optimal allocation is [12,34,67] and [90]. The maximum pages assigned to a student is 113, which is the minimum possible.
Example 2
Input: pages = [10,20,30,40], m = 2
Output: 60
Explanation: The optimal allocation is [10,20,30] and [40]. The maximum pages assigned is minimized to 60.
Example 3
Input: pages = [15,17,20], m = 4
Output: -1
Explanation: There are more students than books, so allocation is not possible.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
12 34 67 90 2
113
10 20 30 40 2
60