{"id":22513461,"url":"https://github.com/emahtab/coin-change-2","last_synced_at":"2025-03-28T01:23:59.164Z","repository":{"id":79525362,"uuid":"207967999","full_name":"eMahtab/coin-change-2","owner":"eMahtab","description":"Coin Change Problem (Total number of ways to make change) Implementation","archived":false,"fork":false,"pushed_at":"2024-10-27T13:05:44.000Z","size":377,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-02T03:19:27.790Z","etag":null,"topics":["coin-change","dynamic-programming","leetcode"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eMahtab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-12T04:57:57.000Z","updated_at":"2024-10-27T13:05:47.000Z","dependencies_parsed_at":"2023-05-10T17:15:50.381Z","dependency_job_id":null,"html_url":"https://github.com/eMahtab/coin-change-2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fcoin-change-2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fcoin-change-2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fcoin-change-2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fcoin-change-2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eMahtab","download_url":"https://codeload.github.com/eMahtab/coin-change-2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245950658,"owners_count":20699106,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coin-change","dynamic-programming","leetcode"],"created_at":"2024-12-07T03:12:25.195Z","updated_at":"2025-03-28T01:23:59.139Z","avatar_url":"https://github.com/eMahtab.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Coin Change 2\n## https://leetcode.com/problems/coin-change-2\n\nYou are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.\n\nReturn the number of combinations that make up that amount. If that amount of money cannot be made up by any combination of the coins, return 0.\n\nYou may assume that you have an infinite number of each kind of coin.\n\nThe answer is guaranteed to fit into a signed 32-bit integer.\n\n \n```\nExample 1:\n\nInput: amount = 5, coins = [1,2,5]\nOutput: 4\nExplanation: there are four ways to make up the amount:\n5=5\n5=2+2+1\n5=2+1+1+1\n5=1+1+1+1+1\n\nExample 2:\n\nInput: amount = 3, coins = [2]\nOutput: 0\nExplanation: the amount of 3 cannot be made up just with coins of 2.\n\nExample 3:\n\nInput: amount = 10, coins = [10]\nOutput: 1\n``` \n\n## Constraints:\n```\n1. 1 \u003c= coins.length \u003c= 300\n2. 1 \u003c= coins[i] \u003c= 5000\n3. All the values of coins are unique.\n4. 0 \u003c= amount \u003c= 5000\n```\n\n\n# Implementation :\n```java\nclass Solution {\n    public int change(int amount, int[] coins) {\n        int[][] dpTable = new int[coins.length + 1][amount + 1];\n\n\tfor (int i = 0; i \u003c= coins.length; i++) {\n\t    dpTable[i][0] = 1; // 1 way to make change for 0\n\t}\n\tfor (int j = 1; j \u003c= amount; j++) {\n            // no way (0) to make change for amount greater than zero with 0 value coin\n\t    dpTable[0][j] = 0; \n\t}\n\n\tfor (int i = 1; i \u003c= coins.length; i++) {\n\t   for (int j = 1; j \u003c= amount; j++) {\n\t\tif (coins[i - 1] \u003e j) {\n\t\t    dpTable[i][j] = dpTable[i - 1][j];\n\t\t} else {\n\t\t    dpTable[i][j] = dpTable[i - 1][j] + dpTable[i][j - coins[i - 1]];\n\t\t}\n\t   }\n\t}\n\treturn dpTable[coins.length][amount];\n    }\n}\n```\n\n## Notes :\nThis problem is same as https://github.com/eMahtab/combination-sum , the only difference is, here we just need to find out how many ways we can make the change, we don't need the actual coin combination which sum to target, just the total number of ways to make the target change.\n#### Recursive solution same as Combination Sum : But TLE\n```java\nclass Solution {\n    public int change(int amount, int[] coins) {\n       int[] result = new int[1];\n       findCombination(coins, amount, 0, result);\n       return result[0];\n    }\n    private void findCombination(int[] candidates, int target, int index, int[] result) {\n        if(target == 0) {\n    \t    result[0]++;\n    \t    return;\n    \t}\n    \tfor(int i = index; i \u003c candidates.length; i++) {\n    \t    if(candidates[i] \u003c= target) {\n    \t       findCombination(candidates, target - candidates[i], i, result);\n    \t    }   \n    \t}\n    }\n}\n```\n\n# References :\nhttps://www.youtube.com/watch?v=nCwfxw3GH-g\n\n## Similar Problem :\nhttps://leetcode.com/problems/coin-change\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fcoin-change-2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femahtab%2Fcoin-change-2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fcoin-change-2/lists"}