Skip to main content
mediumBlind 75

Coin Change

Given an array of coin denominations and a target amount Return the minimum number of coins needed to make up the amount Return -1 if it's not possible to make the amount You have infinite coins of each denomination Example: coins = [1,2,5], amount = 11 => 3 (5+5+1)

I build up from amount zero, not down from the target. Each amount asks which single coin gets it there cheapest.

Examples

You write

coin_change(coins: List[int], amount: int)

  1. Example 1

    Input
    coins = [1,2,5], amount = 11
    returns
    3
  2. Example 2

    Input
    coins = [2], amount = 3
    returns
    -1

The pattern behind it

Arrays & Hashing

I reach for it when

  • You catch yourself scanning the array again for every element.
  • The problem asks about duplicates, pairs, counts or groups.

Say this before you type. Say what the key is and what the value remembers, before you write the loop.

All 127 Arrays & Hashing problems

Dynamic Programming

I reach for it when

  • Brute force repeats the same subproblem.
  • You are asked for a count, a minimum or a maximum.

Say this before you type. Say the state in one sentence, then say which smaller states it reads from.

All 37 Dynamic Programming problems

Meet Coco

Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Sign in free to type with Coco, up to a daily limit. The editor and Run stay open without an account. Anyone can open the editor and run their code.

1Minimum Coins to Make Amountmedium
2Part 2
3Part 3

Each locked part opens in the editor once the part before it passes.

Prep guides that list this problem

Our company tags come from public interview write-ups. None of these is a confirmed question.