Introduction
The Allocate Minimum Number of Pages problem is one of the most important DSA interview questions because it introduces a powerful idea called Binary Search on Answer.
In simple words, this problem asks you to distribute books among students in a fair way, so that the student who reads the most pages reads as little as possible.
This article explains the problem using simple, human language, real-life meaning, and a clear binary search–based solution that interviewers expect.
Real-World Meaning of Book Allocation
Imagine a school teacher who wants to distribute books among students:
Each book has a certain number of pages
Each student must get contiguous books
The teacher wants to make sure no student is overloaded
The goal is to distribute books so that the maximum pages assigned to any student is minimum.
Problem Statement
You are given:
An array where each element represents pages in a book
An integer
mrepresenting number of students
Rules:
Each student must get at least one book
Books must be allocated contiguously
Your task is to minimize the maximum number of pages assigned to any student.
Example
Books: [12, 34, 67, 90]
Students: 2
Output
Minimum maximum pages = 113
Explanation:
Student 1 → [12, 34, 67] = 113 pages
Student 2 → [90] = 90 pages
Before vs After Understanding
Brute Force Thinking (Before)
Try all possible distributions
Compare maximum pages
Extremely slow and impractical
Binary Search Thinking (After)
Search on the answer space
Check if a distribution is possible
Reduce search space step by step
Why Binary Search Works Here
Even though this is not a searching problem, binary search works because:
The answer lies between a minimum and a maximum value
If a distribution is possible for
Xpages, it will also be possible for any value greater than X
This monotonic behavior allows binary search.
What Interviewers Are Actually Testing
Interviewers want to see:
Can you think beyond arrays and indexes?
Do you understand binary search on answer?
Can you convert real-world constraints into code?
This problem tests problem modeling skills.
Key Idea (Very Simple)
The minimum possible answer is the largest single book
The maximum possible answer is the sum of all pages
Use binary search between these two values
Step-by-Step Logic
Set
low= max number of pages in a bookSet
high= sum of all pagesFind
mid(possible answer)Check if books can be allocated with
midas maximum pagesIf possible, try smaller value (move left)
If not possible, try larger value (move right)
Feasibility Check (Very Important)
To check if allocation is possible:
Assign books to students one by one
If pages exceed
mid, assign to next studentIf students required >
m, allocation is not possible
Dry Run Example
Books: [12, 34, 67, 90], Students = 2
Join the conversation! Your thoughts help the community grow.