Ctrl K

Plan Tasks Over Days

Hard
You have a list of tasks with workloads effort, and they must be done in exactly days days. Tasks are done strictly in order: task i can start only after all earlier tasks are finished. At least one task must be done every day. The load of a day is the largest workload among that day's tasks. The load of a plan is the sum of the loads of all its days. Return the minimum load of a plan, or -1 if no plan is possible.
Example 1
effort=[3, 8, 2, 2, 5], days=2 → 11

The best plan does only the task with workload 3 on day one and the rest on day two: 3 + 8 = 11. Splitting into [3, 8] and [2, 2, 5] would give 8 + 5 = 13.

Example 2
effort=[4, 4], days=3 → -1

There are only two tasks for three days, so some day would be left empty.

Example 3
effort=[0, 7, 1, 6], days=4 → 14
Constraints
  • 1 ≤ len(effort) ≤ 300
  • 0 ≤ effort[i] ≤ 1000
  • 1 ≤ days ≤ 10
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsWater Between Walls HardBiggest Solid Panel Block HardProfit From Two Trades HardEvery Way to Space the Words HardCrossing the Cave Hard
loading Python…
Input
effort=[3, 8, 2, 2, 5], days=2
Expected
11

Run checks the first 3 tests in your browser. Submit checks all 96 tests on the server, hidden ones included.