File tree Expand file tree Collapse file tree 2 files changed +52
-1
lines changed Expand file tree Collapse file tree 2 files changed +52
-1
lines changed Original file line number Diff line number Diff line change 1- # 1,501 LeetCode solutions in JavaScript
1+ # 1,502 LeetCode solutions in JavaScript
22
33[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
44
132813281720|[ Decode XORed Array] ( ./solutions/1720-decode-xored-array.js ) |Easy|
132913291721|[ Swapping Nodes in a Linked List] ( ./solutions/1721-swapping-nodes-in-a-linked-list.js ) |Medium|
133013301722|[ Minimize Hamming Distance After Swap Operations] ( ./solutions/1722-minimize-hamming-distance-after-swap-operations.js ) |Medium|
1331+ 1723|[ Find Minimum Time to Finish All Jobs] ( ./solutions/1723-find-minimum-time-to-finish-all-jobs.js ) |Hard|
133113321726|[ Tuple with Same Product] ( ./solutions/1726-tuple-with-same-product.js ) |Medium|
133213331732|[ Find the Highest Altitude] ( ./solutions/1732-find-the-highest-altitude.js ) |Easy|
133313341748|[ Sum of Unique Elements] ( ./solutions/1748-sum-of-unique-elements.js ) |Easy|
Original file line number Diff line number Diff line change 1+ /**
2+ * 1723. Find Minimum Time to Finish All Jobs
3+ * https://leetcode.com/problems/find-minimum-time-to-finish-all-jobs/
4+ * Difficulty: Hard
5+ *
6+ * You are given an integer array jobs, where jobs[i] is the amount of time it takes to complete
7+ * the ith job.
8+ *
9+ * There are k workers that you can assign jobs to. Each job should be assigned to exactly one
10+ * worker. The working time of a worker is the sum of the time it takes to complete all jobs
11+ * assigned to them. Your goal is to devise an optimal assignment such that the maximum working
12+ * time of any worker is minimized.
13+ *
14+ * Return the minimum possible maximum working time of any assignment.
15+ */
16+
17+ /**
18+ * @param {number[] } jobs
19+ * @param {number } k
20+ * @return {number }
21+ */
22+ var minimumTimeRequired = function ( jobs , k ) {
23+ const n = jobs . length ;
24+ const workerTimes = new Array ( k ) . fill ( 0 ) ;
25+ let result = Infinity ;
26+
27+ jobs . sort ( ( a , b ) => b - a ) ;
28+ backtrack ( 0 , 0 ) ;
29+
30+ return result ;
31+
32+ function backtrack ( jobIndex , maxTime ) {
33+ if ( jobIndex === n ) {
34+ result = Math . min ( result , maxTime ) ;
35+ return ;
36+ }
37+
38+ if ( maxTime >= result ) return ;
39+
40+ for ( let i = 0 ; i < k ; i ++ ) {
41+ if ( workerTimes [ i ] + jobs [ jobIndex ] >= result ) continue ;
42+
43+ workerTimes [ i ] += jobs [ jobIndex ] ;
44+ backtrack ( jobIndex + 1 , Math . max ( maxTime , workerTimes [ i ] ) ) ;
45+ workerTimes [ i ] -= jobs [ jobIndex ] ;
46+
47+ if ( workerTimes [ i ] === 0 ) break ;
48+ }
49+ }
50+ } ;
You can’t perform that action at this time.
0 commit comments