in problem, "COINS" find what is wrong in my code in memorization in dynmic implementation

problem Coin link
my below code is giving wrong answer
i am new to dynamic progrming… what is problem with my written follwing code while doing memorisation

    //package PracticeMedium;

//package PracticeMedium;

/*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
 */
//package PracticeMedium;
import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author Hemant Dhanuka
 */
//without memorisation 
class COINS4 {

    static HashMap<Integer, Long> memorisationMap = new HashMap<>();

    public static void main(String[] args) throws Exception {

        Scanner s = new Scanner(System.in);
        while (s.hasNextInt()) {
            int numberWrittenOnCoin = s.nextInt();
            calculateMaxforEachNo(numberWrittenOnCoin);
            if (numberWrittenOnCoin < 12) {
                System.out.println(numberWrittenOnCoin);
            } else {
                System.out.println(memorisationMap.get(numberWrittenOnCoin));
            }
        }
    }

    private static long calculateMaxforEachNo(int num) {

        if (num < 12) {
            return num;
        }

        if (memorisationMap.get(num) != null) {
            return memorisationMap.get(num);
        }
        memorisationMap.put(num, (calculateMaxforEachNo(num / 2) + calculateMaxforEachNo(num / 3) + calculateMaxforEachNo(num / 4)));
        return 0;

    }
}

please tell me what modification required to get Correct answer in my above code, and other alternate solution of these problem to approch and perform memorisation

@hemant_dhanuka I see that you fixed the bug and got AC, good job :slight_smile:

2 Likes