@@ -13,24 +13,7 @@ public int jobScheduling(int[] startTime, int[] endTime, int[] profit) {
13
13
map =new HashMap <>();
14
14
return solveMemoOptimised (0 ,triple ,n );
15
15
}
16
- public static int solveMemoOptimised (int indx ,List <Triple > tp ,int n ){
17
- //Base Case::
18
- if (indx == n ) return 0 ;
19
- if (map .containsKey (indx )){
20
- return map .get (indx );
21
- }
22
- // Choices we have ::: pick or not pick
23
-
24
- int next =getNextIndx (tp ,indx ,n );
25
- int pick =tp .get (indx ).profit +solveMemoOptimised (next ,tp ,n );
26
-
27
- int notPick =solveMemoOptimised (indx +1 ,tp ,n );
28
- map .put (indx ,Math .max (pick ,notPick ));
29
- return Math .max (pick ,notPick );
30
-
31
- }
32
- // Previous Approch : getting tle ::
33
- // public static int solveMemo(int indx,int lasttime,List<Triple> tp){
16
+ // public static int solveMemo(int indx,int lasttime,List<Triple> tp){
34
17
// //Base Case::
35
18
// if(indx == tp.size()) return 0;
36
19
// // Choices we have ::: pick or not pick
@@ -47,6 +30,22 @@ public static int solveMemoOptimised(int indx,List<Triple> tp,int n){
47
30
// map.put(key,Math.max(pick,notPick));
48
31
// return Math.max(pick,notPick);
49
32
// }
33
+ public static int solveMemoOptimised (int indx ,List <Triple > tp ,int n ){
34
+ //Base Case::
35
+ if (indx == n ) return 0 ;
36
+ if (map .containsKey (indx )){
37
+ return map .get (indx );
38
+ }
39
+ // Choices we have ::: pick or not pick
40
+
41
+ int next =getNextIndx (tp ,indx ,n );
42
+ int pick =tp .get (indx ).profit +solveMemoOptimised (next ,tp ,n );
43
+
44
+ int notPick =solveMemoOptimised (indx +1 ,tp ,n );
45
+ map .put (indx ,Math .max (pick ,notPick ));
46
+ return Math .max (pick ,notPick );
47
+
48
+ }
50
49
public static int getNextIndx (List <Triple > tp ,int indx ,int n ){
51
50
int l =indx +1 ;
52
51
int h =n -1 ;
0 commit comments