Skip to content

Commit 19b1534

Browse files
committedApr 10, 2025
Add solution #1335
1 parent 1f50517 commit 19b1534

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed
 

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,236 LeetCode solutions in JavaScript
1+
# 1,237 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1013,6 +1013,7 @@
10131013
1332|[Remove Palindromic Subsequences](./solutions/1332-remove-palindromic-subsequences.js)|Easy|
10141014
1333|[Filter Restaurants by Vegan-Friendly, Price and Distance](./solutions/1333-filter-restaurants-by-vegan-friendly-price-and-distance.js)|Medium|
10151015
1334|[Find the City With the Smallest Number of Neighbors at a Threshold Distance](./solutions/1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance.js)|Medium|
1016+
1335|[Minimum Difficulty of a Job Schedule](./solutions/1335-minimum-difficulty-of-a-job-schedule.js)|Hard|
10161017
1342|[Number of Steps to Reduce a Number to Zero](./solutions/1342-number-of-steps-to-reduce-a-number-to-zero.js)|Easy|
10171018
1351|[Count Negative Numbers in a Sorted Matrix](./solutions/1351-count-negative-numbers-in-a-sorted-matrix.js)|Easy|
10181019
1352|[Product of the Last K Numbers](./solutions/1352-product-of-the-last-k-numbers.js)|Medium|
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* 1335. Minimum Difficulty of a Job Schedule
3+
* https://leetcode.com/problems/minimum-difficulty-of-a-job-schedule/
4+
* Difficulty: Hard
5+
*
6+
* You want to schedule a list of jobs in d days. Jobs are dependent (i.e To work on the ith job,
7+
* you have to finish all the jobs j where 0 <= j < i).
8+
*
9+
* You have to finish at least one task every day. The difficulty of a job schedule is the sum of
10+
* difficulties of each day of the d days. The difficulty of a day is the maximum difficulty of a
11+
* job done on that day.
12+
*
13+
* You are given an integer array jobDifficulty and an integer d. The difficulty of the ith job
14+
* is jobDifficulty[i].
15+
*
16+
* Return the minimum difficulty of a job schedule. If you cannot find a schedule for the jobs
17+
* return -1.
18+
*/
19+
20+
/**
21+
* @param {number[]} jobDifficulty
22+
* @param {number} d
23+
* @return {number}
24+
*/
25+
var minDifficulty = function(jobDifficulty, d) {
26+
const n = jobDifficulty.length;
27+
if (n < d) return -1;
28+
29+
const dp = new Array(d + 1).fill().map(() => new Array(n + 1).fill(Infinity));
30+
dp[0][0] = 0;
31+
32+
for (let days = 1; days <= d; days++) {
33+
for (let i = days; i <= n; i++) {
34+
let maxDifficulty = 0;
35+
for (let j = i - 1; j >= days - 1; j--) {
36+
maxDifficulty = Math.max(maxDifficulty, jobDifficulty[j]);
37+
dp[days][i] = Math.min(dp[days][i], dp[days - 1][j] + maxDifficulty);
38+
}
39+
}
40+
}
41+
42+
return dp[d][n] === Infinity ? -1 : dp[d][n];
43+
};

0 commit comments

Comments
 (0)
Please sign in to comment.