Bootcamps
Masterclasses
Menu
Courses
Account
Login / Sign Up

Allocate Minimum Pages

Medium Acceptance 62% Points 30

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.

Examples
Example 1

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

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

Example 3

Input: pages = [15,17,20], m = 4

Output: -1

Explanation: There are more students than books, so allocation is not possible.

Constraints
  • 1 = pages.length = 105
  • 1 = pages[i] = 105
  • 1 = m = pages.length
Topics
Binary Search
Companies
eBay
Added 19 Jul 2026 62% acceptance
Ln 1, Col 1Sign in to save your code
12 34 67 90
2
113