All problems
0273MediumArrayBinary Search

Smallest Binder Comb for the Pass Budget

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1283Find the Smallest Divisor Given a Threshold

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A print shop binds jobs on a comb machine. pages[i] is the page count of job i, and every job is bound on its own.

A comb of size d grips at most d pages per pass, so job i occupies ceil(pages[i] / d) passes: the machine keeps taking full bites of d pages and a final short bite still uses up a whole pass.

Combs are stocked in every whole size from 1 upward, and the shop is prepared to run at most budget passes in total across all the jobs. Return the smallest comb size that keeps the total number of passes at or below budget.

budget is never smaller than the number of jobs, so some comb size always works.

Examples

Example 1

Input
pages = [5, 7], budget = 4
Output
4

A comb of 4 takes job 0 in two passes, of 4 pages then 1, and job 1 in two passes, of 4 pages then 3. That is 4 passes altogether, which the budget allows.

Example 2

Input
pages = [4, 8, 12], budget = 6
Output
4

A comb of 4 grips job 0 in a single pass, job 1 in two and job 2 in three, for exactly 6 passes.

Example 3

Input
pages = [17], budget = 1
Output
17

A comb of 17 binds the one 17-page job in a single pass, which fits a budget of 1 pass.

Constraints

  • 1 <= pages.length <= 5 * 10^4
  • 1 <= pages[i] <= 10^6
  • pages.length <= budget <= 10^6

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def smallest_binder_comb(pages: list[int], budget: int) -> int:
Java
public int smallestBinderComb(int[] pages, int budget)
September 7
Apply