Skip to content

ORIGINAL CODING QUESTION

Minimum batch processing rate

Each hour processes at most rate units from one workload; leftover hourly capacity is not shared. Find the minimum positive integer rate finishing all workloads within h hours.

Open practice workspace

Original exercise · medium. Editorial role relevance does not imply a company has asked this question.

Input and output

n, then n positive workloads, then h.

Constraints

1 ≤ n ≤ 200; 1 ≤ workload ≤ 100; n ≤ h ≤ 20,000.

Example 1

Input

4 3 6 7 11 8

Output

4

Rate 4 requires 8 hours.

Example 2

Input

2 5 5 2

Output

5

Rate 5 finishes in two hours.

Explain your approach

Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?

Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.

Hint 1

A larger rate never requires more hours.

Hint 2

Required hours equal the sum of ceiling(workload/rate).

Hint 3

Binary search rates from 1 to the largest workload.

Practice this question

Save your work privately, explain decisions and return to your revision queue.

Open practice workspaceBrowse the question library →