MCPcopy Index your code
hub / github.com/neetcode-gh/leetcode / dfs

Method dfs

java/1335-minimum-difficulty-of-a-job-schedule.java:11–27  ·  view source on GitHub ↗
(int i, int d, int cur_max, int[] jobDiff)

Source from the content-addressed store, hash-verified

9 }
10
11 private int dfs(int i, int d, int cur_max, int[] jobDiff){
12 if(i == jobDiff.length)
13 return (d == 0)? 0: (int)1e9;
14 if(d == 0)
15 return (int)1e9;
16 String cur_state = i + "," + d + "," + cur_max;
17 if(cache.containsKey(cur_state))
18 return cache.get(cur_state);
19
20 cur_max = Math.max(cur_max, jobDiff[i]);
21 int res = Math.min(
22 dfs(i + 1, d, cur_max, jobDiff),
23 cur_max + dfs(i + 1, d - 1, -1, jobDiff)
24 );
25 cache.put(cur_state, res);
26 return res;
27 }
28}

Callers 1

minDifficultyMethod · 0.95

Calls 2

getMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected