tinycodinglm / cp /cp-10025.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 12)
3c88a0f verified
|
Raw History Blame Contribute Delete
1.77 kB
{"type": "session", "harness": "opencode", "id": "cp-10025", "name": "LeetCode 0518: Coin Change 2"}
{"type": "message", "message": {"role": "system", "content": "You are an expert LeetCode problem solver. You solve problems efficiently with clean code."}}
{"type": "message", "message": {"role": "user", "content": "Problem: Coin Change II (Difficulty: Medium)\nTags: Array, Dynamic Programming\n\nYou are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.\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.\nYou may assume that you have an infinite number of each kind of coin.\nThe answer is guaranteed to fit into a signed 32-bit integer.\n\nExample 1:\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:\nInput: amount = 3, coins = [2]\nOutput: 0\nExplanation: the amount of 3 cannot be made up just with coins of 2.\n\nExample 3:\nInput: amount = 10, coins = [10]\nOutput: 1\n\nConstraints:\n- 1 <= coins.length <= 300\n- 1 <= coins[i] <= 5000\n- All the values of coins are unique.\n- 0 <= amount <= 5000"}}
{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n * m)\n# Space: O(m)\n\nclass Solution(object):\n def change(self, amount, coins):\n \"\"\"\n :type amount: int\n :type coins: List[int]\n :rtype: int\n \"\"\"\n dp = [0] * (amount+1)\n dp[0] = 1\n for coin in coins:\n for i in range(coin, amount+1):\n dp[i] += dp[i-coin]\n return dp[amount]\n\n"}}