File tree Expand file tree Collapse file tree 1 file changed +62
-0
lines changed Expand file tree Collapse file tree 1 file changed +62
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java.util.HashMap;
2
+ public class Solution {
3
+
4
+ public static long bytelandian(long n, HashMap<Long, Long> memo) {
5
+ // Write your code here
6
+
7
+ if(n<=1)
8
+ {
9
+ return n;
10
+ }
11
+
12
+
13
+
14
+ long ans2=Integer.MIN_VALUE;
15
+
16
+ if(!memo.containsKey(n/2)) {
17
+ ans2=bytelandian(n/2, memo);
18
+
19
+ }
20
+ else
21
+ {
22
+ ans2= memo.get(n/2);
23
+ }
24
+
25
+ long ans3=Integer.MIN_VALUE;
26
+
27
+ if(!memo.containsKey(n/3)) {
28
+ ans3=bytelandian(n/3, memo);
29
+
30
+ }
31
+ else
32
+ {
33
+ ans3= memo.get(n/3);
34
+ }
35
+
36
+
37
+ long ans4=Integer.MIN_VALUE;
38
+
39
+ if(!memo.containsKey(n/4)) {
40
+ ans4=bytelandian(n/4, memo);
41
+
42
+ }
43
+ else
44
+ {
45
+ ans4= memo.get(n/4);
46
+ }
47
+
48
+ long sum = ans2+ans3+ans4;
49
+ long var = Math.max(n, sum);
50
+ memo.put(n, var);
51
+
52
+ return memo.get(n);
53
+ }
54
+
55
+
56
+ public static void main(String[] args) {
57
+ HashMap<Long,Long> map = new HashMap<>();
58
+ long ans = bytelandian(12,map);
59
+ System.out.println(ans);
60
+ }
61
+
62
+ }
You can’t perform that action at this time.
0 commit comments