For Problem Statement refer: https://www.hackerrank.com/challenges/coin-change/problem

Solution

    public static long getWays(int n, List<Long> c) {
    // Write your code here 

        long[] dp = new long[n+1];
        dp[0] = 1;
        for(int i=0;i<c.size();i++)
        {
            int coin = c.get(i).intValue();
            for(int j=1;j<=n;j++)
            {
                if(j >= coin)
                {
                    dp[j] = dp[j] + dp[j-coin];
                }
            }
        }
        return dp[n];
   
    }

Code Explanation Refer: https://www.youtube.com/watch?v=jaNZ83Q3QGc&list=PLSewJMV0ZjOcrJ8BdJYUsf4N1BfvTReQ3&index=1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s