Allocate Minimum Pages
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Amazon OA from September 2026 asks you to allocate books to students and minimize the biggest load. The first instinct is to hunt for a clever data structure. There isn't one. The array stays an array, and the real structure is a search range of possible answers, with a plain running sum inside a feasibility check. If you've seen binary search on the answer, this is that. If you haven't, you've got a short window to learn it. StealthCoder sits invisibly on your screen as a safety net if your mind goes blank mid-assessment.
The problem
You are given an array pages, where pages[i] is the number of pages in the i-th book, and an integer students. Allocate every book to exactly one student so that: Each student receives at least one book. Each student receives one contiguous group of books. The original book order is preserved. Return the minimum possible value of the maximum pages assigned to any student. Return -1 when there are more students than books. Function allocateMinimumPages(pages: int[], students: int) → long Examples Example 1 pages = [12,34,67,90] students = 2 return = 113 Allocate [12,34,67] and [90]. The larger load is 113, and no valid split has a smaller maximum. Example 2 pages = [10,20,30,40] students = 2 return = 60 The optimal groups are [10,20,30] and [40]. Example 3 pages = [10,20] students = 3 return = -1 Three nonempty contiguous groups cannot be formed from two books. Constraints 1 <= pages.length <= 100000. 1 <= pages[i] <= 10^6. 1 <= students <= 100000.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is binary search on the answer, not on the array. The lower bound is max(pages), since one student must hold the biggest book. The upper bound is sum(pages). For a candidate limit, greedily walk the books, adding to the current student until the next book would exceed the limit, then start a new student. Count students used. If the count is at most students, the limit works, so search lower. Otherwise search higher. Complexity is O(n log(sum)). Pitfalls: forgetting the -1 case when students exceeds the book count, starting the lower bound at 1 or 0 so a single book can't fit, and using 32-bit ints. The sum can reach 10^11, so use long. Also return the smallest feasible limit, not the first one found. If the greedy check slips under pressure, StealthCoder is the hedge during the live OA.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Allocate Minimum Pages cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as split array largest sum. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Allocate Minimum Pages FAQ
What's the trick in Allocate Minimum Pages?+
Binary search on the answer. Search the range from the largest single book to the total pages. For each midpoint, greedily count how many students you need with that cap. If it fits within the student count, shrink the range downward. Otherwise raise it.
How hard is this really for an Amazon OA?+
Medium to hard if you haven't seen binary search on the answer, easy once you have. The code is short, about 25 lines. The difficulty is recognizing that the answer itself is monotonic, so you can search over it instead of over the array.
Why can't I just use dynamic programming?+
You can, but it's too slow. A DP over books and students is roughly O(n^2 * k) naively, which fails with n up to 100000. Binary search with a linear greedy check runs in O(n log(sum)) and fits the constraints comfortably.
What edge cases should I test?+
Test students greater than the number of books, which returns -1. Test students equal to the number of books, where the answer is the max book. Test one student, where the answer is the total sum. Also test a large input to confirm you're using long, not int.
How do I prepare for this in 48 hours?+
Write the feasibility function first, then wrap it in a binary search loop. Practice two or three related problems that search over an answer range, like split array largest sum or ship packages. Once you spot the monotonic condition, the template repeats.