The Coin Change Problem

  • + 0 comments

    Java O(n*m)

    public static long getWays(int n, List<Long> c) {
            long[] ways = new long[n + 1];
            ways[0] = 1;
    
            for (long coin : c) {
                for (int i = (int) coin; i <= n; i++) {
                    ways[i] += ways[i - (int) coin];
                }
            }
    
            return ways[n];
        }