Skip to content

ORIGINAL CODING QUESTION

Minimum review capacity

Review n positive workloads in order across at most d days. Each day takes a contiguous group. Find the smallest daily capacity that can complete every workload.

Open practice workspace

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

Input and output

n, then n positive workloads, then d. Print minimum capacity.

Constraints

1 ≤ n ≤ 10,000; 1 ≤ workload ≤ 10,000; 1 ≤ d ≤ n.

Example 1

Input

5
2 3 4 5 6
2

Output

11

Capacity 11 allows [2,3,4] and [5,6]. Capacity 10 needs three days.

Example 2

Input

3
3 1 2
3

Output

3

Capacity must be at least the largest workload, 3.

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

Capacity lies between the maximum workload and the total workload.

Hint 2

For a proposed capacity, greedily count how many days are needed.

Hint 3

Binary search capacity; move the upper boundary when the greedy schedule uses at most d days.

Practice this question

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

Open practice workspaceBrowse the question library →