Allocate Minimum Pages using Binary Search on Answer
📖 Scenario: You are managing a library where books are arranged in a row. Each book has a certain number of pages. You want to allocate these books to a fixed number of students such that each student gets a continuous sequence of books. Your goal is to minimize the maximum number of pages assigned to any student.This is a common problem in resource allocation where fairness and balance are important.
🎯 Goal: Build a TypeScript program that uses binary search on the answer to find the minimum possible maximum pages allocated to a student.You will create the data structure for books, set the number of students, implement the binary search logic, and finally print the minimum maximum pages.
📋 What You'll Learn
Create an array called
books with the exact values [12, 34, 67, 90]Create a variable called
students and set it to 2Write a function called
isPossible that takes mid as input and returns true if allocation is possible with max pages <= mid, else falseUse binary search between the max pages of a single book and the sum of all pages to find the minimum max pages
Print the final minimum maximum pages using
console.log💡 Why This Matters
🌍 Real World
This problem models fair resource allocation such as dividing tasks, workloads, or resources among people or machines to balance load.
💼 Career
Understanding binary search on answer is useful in software engineering roles involving optimization, scheduling, and system design.
Progress0 / 4 steps