Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Allocate Minimum Pages

Medium Acceptance 62.00% Points 30.00

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.

Hints
Hint 1
N/A
Constraints
  • 1 = pages.length = 105
  • 1 = pages[i] = 105
  • 1 = m = pages.length
Companies
eBay
Topics
Binary Search
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions