Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Minimum Coins Dynamic Programming
00:00
5 left

Minimum Coins Dynamic Programming

MediumPython

Problem

A Nissan Motor payment kiosk accepts a fixed set of coin denominations. Given the denominations and a target amount, return the minimum number of coins needed to produce that amount. Each denomination may be used any number of times. Return -1 if the amount cannot be formed.

Formal Specification

Implement coin_change(coins, amount), where coins is a list of positive integers and amount is a non-negative integer. Return an integer representing the smallest number of coins whose values sum to amount, or -1 when no valid combination exists.

Constraints

  • 1 <= len(coins) <= 12
  • 1 <= coins[i] <= 10^4
  • 0 <= amount <= 10^4
  • Coin denominations may be used repeatedly.
  • Duplicate denominations may be present.

Function Signature

def coin_change(coins, amount):
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

You need to log in / sign up to run or submit.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.