---
id: 6a1d9f98e819ed70a0e994e0
title: "Challenge 334: Exact Change"
challengeType: 28
dashedName: challenge-334
---

# --description--

Given an integer amount in cents, return the number of distinct ways to make exact change using pennies (1 cent), nickels (5 cents), dimes (10 cents), and quarters (25 cents).

# --hints--

`exactChange(3)` should return `1`.

```js
assert.equal(exactChange(3), 1);
```

`exactChange(9)` should return `2`.

```js
assert.equal(exactChange(9), 2);
```

`exactChange(17)` should return `6`.

```js
assert.equal(exactChange(17), 6);
```

`exactChange(39)` should return `24`.

```js
assert.equal(exactChange(39), 24);
```

`exactChange(61)` should return `73`.

```js
assert.equal(exactChange(61), 73);
```

`exactChange(99)` should return `213`.

```js
assert.equal(exactChange(99), 213);
```

# --seed--

## --seed-contents--

```js
function exactChange(amount) {

  return amount;
}
```

# --solutions--

```js
function exactChange(amount) {
  const coins = [1, 5, 10, 25];
  const dp = new Array(amount + 1).fill(0);
  dp[0] = 1;

  for (const coin of coins) {
    for (let i = coin; i <= amount; i++) {
      dp[i] += dp[i - coin];
    }
  }

  return dp[amount];
}
```
