You are given coins of different denominations and a total amount of money amount. Write a function to compute 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.
You may assume that you have an infinite number of each kind of coin.
 
Example 1:
Input: coins = [1,2,5], amount = 11
Output: 3
Explanation: 11 = 5 + 5 + 1

Example 2:
Input: coins = [2], amount = 3
Output: -1

Example 3:
Input: coins = [1], amount = 0
Output: 0

Example 4:
Input: coins = [1], amount = 1
Output: 1

Example 5:
Input: coins = [1], amount = 2
Output: 2

 
Constraints:

1 <= coins.length <= 12
1 <= coins[i] <= 231 - 1
0 <= amount <= 104

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

def _disabled_input(*args, **kwargs):
    raise RuntimeError("input() is disabled in callable mode")
builtins.input = _disabled_input

ns = {"__name__": "__judge__"}  # prevent if __name__ == "__main__" blocks
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'import math\nfrom functools import lru_cache \n\nclass Solution:\n\n       \n    \n    ### Iterative DFS, with optimizations.  very fast\n    def coinChange(self, coins: List[int], amount: int) -> int:\n        if not coins or amount < 0:\n            return -1\n        \n        stack = [(0,0)]  # sum, coinCount\n        answer = math.inf\n        \n        # !! n.b, sorting small->big so stack processing searches largest first\n        sortedCoins = sorted(coins) \n        # !! n.b. prune search tree to prevent re-searching same sums\n        visited = set()\n        \n        while stack:\n            (sum, coinCount) = stack.pop()\n            # print(\'sum:{}, coinCount:{}, answer:{}\'.format(sum, coinCount, answer))\n            \n            if (sum, coinCount) in visited:\n                pass\n            elif coinCount >= answer:\n                pass\n            elif sum == amount:\n                answer = min(answer,coinCount)\n            elif sum > amount:\n                pass\n            else:\n                \n                \n                for c in sortedCoins:\n                    if ( \n                        (sum+c) <= amount and\n                        # !! n.b. ensure still possible to beat best answer \n                        # !! with this coin\n                        amount < (sum + (c*(answer-coinCount)))\n                    ):\n                        stack.append((sum+c, coinCount+1))\n                        \n            visited.add((sum, coinCount))\n                \n        if answer == math.inf:\n            return -1\n        else:\n            return answer\n    \n    \n    \n#     ### Iterative DFS.  Brute force won\'t finish on large trees\n#     def coinChange(self, coins: List[int], amount: int) -> int:\n#         stack = [(0,0)]    # (sum, count)\n#         # visited = set()\n#         answer = math.inf\n        \n#         while stack:\n#             node = stack.pop()\n#             # print(node)\n            \n#             if node[0] == amount:\n#                 answer = min(answer, node[1])\n#             elif node[0] > amount:\n#                 pass\n#             else:\n#                 for coin in coins:\n#                     stack.append( (node[0]+coin, node[1]+1)  )\n                    \n#         if answer == math.inf:\n#             return -1\n#         else:\n#             return answer\n        \n        \n#     ### Recursive DFS with memoization\n#     def coinChange(self, coins: List[int], amount: int) -> int:\n\n#         @lru_cache(maxsize=None)\n#         def dfs(remainder):\n#             if remainder < 0:\n#                 return math.inf\n#             elif remainder == 0:\n#                 return 0\n#             else:\n#                 least = math.inf\n#                 for coin in coins:\n#                     least = min(least, dfs(remainder - coin) + 1)\n#                 return least\n        \n#         res = dfs(amount)\n#         if res == math.inf:\n#             return -1\n#         else:\n#             return res\n    \n#     def coinChange(self, coins: List[int], amount: int) -> int:\n        \n#         def backtrack(remainder):\n#             # print(remainder)\n#             if remainder in memo:\n#                 return memo[remainder]\n#             elif remainder < 0:\n#                 return math.inf\n#             elif remainder == 0:\n#                 memo[remainder] = 0\n#                 return memo[remainder]\n#             else:\n#                 least = math.inf\n#                 for coin in coins:\n#                     least = min(least, backtrack(remainder - coin) + 1)\n#                 memo[remainder] = least\n#                 return memo[remainder]    \n        \n#         memo = collections.defaultdict(int)\n#         res = backtrack(amount)\n#         if res == math.inf:\n#             return -1\n#         else:\n#             return res\n        \n        \n#     def coinChange(self, coins: List[int], amount: int) -> int:\n#         if not coins or amount < 0:\n#             return -1\n        \n#         @lru_cache(maxsize=None)\n#         def dfs(sum, count):\n#             # print(\\"sum:{}, count:{}\\".format(sum, count))\n#             if count >= self.ans:\n#                 return\n#             elif sum == amount:\n#                 self.ans = min(self.ans, count)\n#                 return\n#             elif sum > amount:\n#                 return\n#             else:\n#                 for c in sortedCoins:\n#                     dfs(sum+c, count+1)\n                    \n#         sortedCoins = sorted(coins, reverse=True)\n#         self.ans = math.inf\n#         dfs(0,0)\n#         if self.ans == math.inf:\n#             return -1\n#         else:\n#             return self.ans\n        \n    \n#     ### BFS\n#     def coinChange(self, coins: List[int], amount: int) -> int:  \n#         if not coins or amount < 0:\n#             return -1\n        \n#         visited = [False]*(amount+1)\n#         parentNodes = [0]\n#         level = -1\n        \n#         while parentNodes:\n#             level += 1\n#             childNodes = []\n#             for node in parentNodes:\n#                 if visited[node]:\n#                     pass\n#                 elif node == amount:\n#                     return level\n#                 elif node > amount:\n#                     pass\n#                 else:\n#                     for c in coins:\n#                         if node+c <= amount:\n#                             childNodes.append(node+c)\n#                 visited[node] = True      \n                \n#             parentNodes = childNodes\n            \n#         return -1\n\n    \n#     ### Dynamic programming\n#     def coinChange(self, coins: List[int], amount: int) -> int:\n#         maxint = math.inf\n        \n#         # one slot for each amount, up to amount. \n#         dp = [0] + [maxint]*amount\n        \n#         for i in range(1,amount+1):\n#             dp[i] = min([(1+dp[i-c]) for c in coins if i>=c] + [maxint])\n            \n#         if dp[amount] == math.inf:\n#             return -1\n#         else:\n#             return dp[amount]\n        \n    \n### Recursive w/memoization    \n#     def coinChange(self, coins: List[int], amount: int) -> int:\n#         sortedCoins = sorted(coins, reverse=True)\n#         result = self.recurse(amount, tuple(sortedCoins))\n        \n#         if result == math.inf:\n#             result = -1\n        \n#         return result\n        \n#     @lru_cache(maxsize=None)\n#     def recurse(self, amount: int, coins: tuple) -> int:\n#         # print(amount)\n#         if amount < 0:\n#             return math.inf\n#         elif amount == 0:\n#             return 0\n#         else:\n#             least = math.inf\n#             for c in coins:\n#                 val = self.recurse(amount-c, coins)\n#                 if val < math.inf:\n#                     # print(\'{} = {}\'.format(amount-c, val))\n#                     least = min(least, val)\n#             return least + 1\n                \n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

_target = None
_fn_name = 'coinChange'
if _fn_name:
    if "Solution" in ns:
        try:
            _obj = ns["Solution"]()
            if hasattr(_obj, _fn_name):
                _target = getattr(_obj, _fn_name)
        except Exception:
            _target = None
    if _target is None and _fn_name in ns and callable(ns[_fn_name]):
        _target = ns[_fn_name]
# Fallback: if there's exactly one user-defined function, use it
if _target is None:
    _cands = [v for k, v in ns.items() if callable(v) and getattr(v, "__module__", "") in ("__judge__", "__main__")]
    _user_funcs = [c for c in _cands if getattr(c, "__name__", "").startswith("_") is False]
    if len(_user_funcs) == 1:
        _target = _user_funcs[0]
if _target is None:
    raise RuntimeError(f"Could not resolve callable '{_fn_name}'")

_raw = sys.stdin.read().strip()
if _raw:
    _parsed = json.loads(_raw)
    if isinstance(_parsed, dict):
        _kwargs = _parsed.get("kwargs", {})
        _args = _parsed.get("args", [])
    else:
        _args, _kwargs = _parsed, {}
else:
    _args, _kwargs = [], {}
if not isinstance(_args, (list, tuple)):
    _args = [_args]
_res = _target(*_args, **_kwargs)
try:
    sys.stdout.write(repr(_res) + "\n")
except Exception:
    pass

```

Measured memory_bytes: 6674