Minimum Sum of Daily Job-Difficulty Maxima

Quick Overview

Minimum Sum of Daily Job-Difficulty Maxima. Finish the jobs in their given dependency order over exactly d days, completing at least one job each day.

Minimum Sum of Daily Job-Difficulty Maxima

Company: Microsoft

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Other

### Problem Finish the jobs in their given dependency order over exactly d days, completing at least one job each day. Each day costs the maximum difficulty of its jobs. Return the smallest sum of daily costs, or -1 when an exact d-day schedule is impossible. ```cpp class Solution { public: int minDifficulty(vector<int>& jobDifficulty, int d); }; ``` ### Examples **Example 1:** ```text Input: jobDifficulty = [2,4,1], d = 2 Output: 5 Explanation: Do the first two jobs on day1 for cost4, then the last for cost1. The other cut costs2+4=6. ``` **Example 2:** ```text Input: jobDifficulty = [2,5], d = 3 Output: -1 Explanation: Two jobs cannot fill three nonempty days. ``` ### Constraints - There are 1 to 300 jobs, each with difficulty in `[0,1000]`. - d is an integer between 1 and 10. ### Contract considerations Daily cost is a maximum, not a sum of the jobs in that day. ```hint Read the boundary condition Use exactly the requested number of nonempty days and preserve job order. Account for impossible schedules and zero-difficulty jobs. ``` ### Boundary reminders Daily cost is a maximum, not a sum of the jobs in that day.

Overview: Minimum Sum of Daily Job-Difficulty Maxima. Finish the jobs in their given dependency order over exactly d days, completing at least one job each day.

Microsoft logo
Microsoft
Source window: 0–3 months · as of Oct 21, 2026
hardSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Finish the jobs in their given dependency order over exactly d days, completing at least one job each day. Each day costs the maximum difficulty of its jobs. Return the smallest sum of daily costs, or -1 when an exact d-day schedule is impossible.

class Solution {
public:
    int minDifficulty(vector<int>& jobDifficulty, int d);
};

Examples

Example 1:

Input: jobDifficulty = [2,4,1], d = 2
Output: 5
Explanation: Do the first two jobs on day1 for cost4, then the last for cost1. The other cut costs2+4=6.

Example 2:

Input: jobDifficulty = [2,5], d = 3
Output: -1
Explanation: Two jobs cannot fill three nonempty days.

Constraints

  • There are 1 to 300 jobs, each with difficulty in [0,1000] .
  • d is an integer between 1 and 10.

Contract considerations

Daily cost is a maximum, not a sum of the jobs in that day.

Boundary reminders

Daily cost is a maximum, not a sum of the jobs in that day.