Skip to content

Instantly share code, notes, and snippets.

@ramseylove
ramseylove / minChangeRecusive.js
Last active February 27, 2022 13:39
minimum change using recursion
function minNumberOfCoinsForChange(n, denoms) {
if (n === 0) return 0
if (n < 0) return Infinity
let coins = Infinity
for (const denom of denoms) {
// +1 handling constant of min of 1 coin if change possible
coins = Math.min(coins, 1 + minNumberOfCoinsForChange(n-denom, denoms))