Skip to content

Commit 014b3c1

Browse files
authored
Update 1723-find-minimum-time-to-finish-all-jobs.js
1 parent b6c24d1 commit 014b3c1

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

1723-find-minimum-time-to-finish-all-jobs.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,41 @@ const minimumTimeRequired = function (jobs, k) {
4545
dfs(0)
4646
return minLongestWorkingTime
4747
}
48+
49+
// another
50+
51+
/**
52+
* @param {number[]} jobs
53+
* @param {number} k
54+
* @return {number}
55+
*/
56+
const minimumTimeRequired = function(jobs, k) {
57+
return solution(jobs, k)
58+
};
59+
60+
function solution(jobs, k) {
61+
const n = jobs.length
62+
let res = Infinity, arr = Array(k).fill(0)
63+
64+
let start = 0
65+
bt(0)
66+
return res
67+
68+
function bt(idx) {
69+
start++
70+
if(idx === n) {
71+
res = Math.min(res, Math.max(...arr))
72+
return
73+
}
74+
const visited = new Set()
75+
for(let j = start; j < start + k; j++) {
76+
const i = j % k
77+
if(visited.has(arr[i])) continue
78+
if(arr[i] + jobs[idx] > res) continue
79+
visited.add(arr[i])
80+
arr[i] += jobs[idx]
81+
bt(idx + 1)
82+
arr[i] -= jobs[idx]
83+
}
84+
}
85+
}

0 commit comments

Comments
 (0)