Like for 36 what would be the answer?
Can you give some more test cases?
Like if 18 is given it will be broken into 9,6,4? I want to ask 18/4 will be valid here?
What is the error in my code?
When I am using Top DOwn or Bottom Up, it is giving run error
static HashMap<Integer, Long> map = new HashMap<Integer, Long>();
public static long exchange(int n) {
if (n == 0) {
return 0;
}
if (map.containsKey(n)) {
return map.get(n);
}
map.put(n, Math.max(n, exchange(n / 2) + exchange(n / 3) + exchange(n / 4)));
return map.get(n);
}
Yeah , it showed out of heap space. So whenever constraints are big, we should use hashmap???
Was my code alright then???
Q whenever constraints are big, we should use hashmap???
yes
Q Was my code alright then???
yes
I had one more doubt to ask
How do I tackle these types of error?
I know typecasting can help but inside arr[here…] it requires int
and I want to put long here
for(long i=12; i<=n; i++){
I should be an integer . becuzz Arrays Ka indexing long data Type se nhi hota h
got it ??
Haan but iss question ke case mei i could go upto long… tab kya karein?
Koi tareeka hai jisse long type ke index array mei access kar sake?
Q Koi tareeka hai jisse long type ke index array mei access kar sake?
Answer Nope
And arraylist ke saath bhi same case hoga?
Arraylist al = new ArrayList<>();
al.get(i);// then i should also be of type int or it can be long?