{"id":22513458,"url":"https://github.com/emahtab/coin-change","last_synced_at":"2026-03-19T23:02:41.401Z","repository":{"id":79525360,"uuid":"442954270","full_name":"eMahtab/coin-change","owner":"eMahtab","description":null,"archived":false,"fork":false,"pushed_at":"2024-10-27T13:40:38.000Z","size":4,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-02T03:19:27.818Z","etag":null,"topics":["coin-change","dynamic-programming","leetcode"],"latest_commit_sha":null,"homepage":"","language":null,"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":"2021-12-30T03:21:43.000Z","updated_at":"2024-10-27T13:40:41.000Z","dependencies_parsed_at":"2023-05-10T17:00:39.550Z","dependency_job_id":null,"html_url":"https://github.com/eMahtab/coin-change","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","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fcoin-change/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fcoin-change/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fcoin-change/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eMahtab","download_url":"https://codeload.github.com/eMahtab/coin-change/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245950660,"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:24.894Z","updated_at":"2026-01-06T08:44:28.703Z","avatar_url":"https://github.com/eMahtab.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Coin Change\n## https://leetcode.com/problems/coin-change\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 fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1.\n\nYou may assume that you have an infinite number of each kind of coin.\n\n``` \nExample 1:\n\nInput: coins = [1,2,5], amount = 11\nOutput: 3\nExplanation: 11 = 5 + 5 + 1\n\nExample 2:\n\nInput: coins = [2], amount = 3\nOutput: -1\n\nExample 3:\n\nInput: coins = [1], amount = 0\nOutput: 0\n``` \n\n## Constraints:\n```\n1. 1 \u003c= coins.length \u003c= 12\n2. 1 \u003c= coins[i] \u003c= 231 - 1\n3. 0 \u003c= amount \u003c= 104\n```\n\n# Implementation 1a : Dynamic Programming\n```java\npublic class Solution {\n  public int coinChange(int[] coins, int amount) {\n    int[] dp = new int[amount + 1];\n    Arrays.fill(dp, Integer.MAX_VALUE);\n    dp[0] = 0;\n    for (int i = 1; i \u003c= amount; i++) {\n      for (int j = 0; j \u003c coins.length; j++) {\n        if (coins[j] \u003c= i) {\n            if(dp[i-coins[j]] != Integer.MAX_VALUE) {\n              dp[i] = Math.min(dp[i], dp[i - coins[j]] + 1);   \n            }\n        }\n      }\n    }\n    return dp[amount] == Integer.MAX_VALUE ? -1 : dp[amount];\n  }\n}\n```\n\n# Implementation 1b : Dynamic Programming\n```java\npublic class Solution {\n  public int coinChange(int[] coins, int amount) {\n    int max = amount + 1;\n    int[] dp = new int[amount + 1];\n    Arrays.fill(dp, max);\n    dp[0] = 0;\n    for (int i = 1; i \u003c= amount; i++) {\n      for (int j = 0; j \u003c coins.length; j++) {\n        if (coins[j] \u003c= i) {\n          dp[i] = Math.min(dp[i], dp[i - coins[j]] + 1);\n        }\n      }\n    }\n    return dp[amount] \u003e amount ? -1 : dp[amount];\n  }\n}\n```\n\n# References :\nhttps://www.youtube.com/watch?v=jgiZlGzXMBw\n\n## Similar Problem :\nhttps://leetcode.com/problems/coin-change-2\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fcoin-change","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femahtab%2Fcoin-change","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fcoin-change/lists"}