Allocate Minimum Pages using Binary Search on Answer
📖 Scenario: You are a librarian who needs to allocate books to students. Each book has a certain number of pages. You want to assign books to students so that the maximum number of pages assigned to any student is as small as possible.This helps keep the workload balanced among students.
🎯 Goal: Build a program that finds the minimum possible maximum pages assigned to a student by using binary search on the answer.
📋 What You'll Learn
Create a slice called
books with these exact page counts: 100, 200, 300, 400Create an integer variable called
students and set it to 2Write a function
isPossible that takes books, students, and a max page limit, and returns true if allocation is possibleUse binary search between the max single book pages and sum of all pages to find the minimum max pages
Print the minimum max pages after allocation
💡 Why This Matters
🌍 Real World
This problem models distributing tasks or workloads evenly among workers to avoid overload.
💼 Career
Understanding binary search on answer is useful in optimization problems common in software engineering and coding interviews.
Progress0 / 4 steps