Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Minimum Coins Change

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Minimum Coins Change. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Pinterest promotion credits can be represented using denominations such as whole-dollar coin values. Given an array of available coin denominations and a nonnegative credit amount, return the minimum number of coins required to make that amount. Each denomination may be used unlimited times. Return -1 if the amount cannot be formed.

Formal Specification

Implement coin_change(coins, amount):

  • Input coins: a list of distinct positive integers representing available denominations.
  • Input amount: a nonnegative integer representing the target credit amount.
  • Output: an integer containing the minimum number of coins, or -1 when no combination produces amount.

The order of coins does not matter, and using the same coin denomination multiple times is allowed.

Constraints

  • 1 <= len(coins) <= 12
  • 1 <= coins[i] <= 10^4
  • 0 <= amount <= 10^4
  • Coin denominations are distinct

Function Signature

def coin_change(coins, amount):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output