Coin Change

Medium

Coin Change Problem Description

Problem Statement

Given an array of distinct positive integers

coins
representing various coin denominations and a non-negative integer
amount
, determine the number of ways to make change for the amount using the available coin denominations. The goal is to find the minimum number of coins required to sum up to the given amount.

Rules and Constraints

  • The input array
    coins
    contains distinct positive integers, each representing a coin denomination.
  • The
    amount
    is a non-negative integer, and it is guaranteed that there is a way to make change for it with the available coin denominations.
  • You can assume the input arrays will not be empty, and the
    amount
    will not be zero.
  • The function should return the minimum number of coins required to reach the given
    amount
    , or throw an error if it's impossible to make change.
  • The time complexity for solving this problem should be O(amount * coins.length), where
    coins.length
    is the number of distinct coin denominations.
  • The space complexity should be O(amount), as we need to use dynamic programming to solve this problem iteratively.

Note: The order in which the coins are selected does not matter, and you can use each coin denomination any number of times to make change.

Example

Input: {"input_data":[1,2,3]} Output: [1,2,3]

CompaniesGoogleMetaAmazon
JavaScript

Login to write code

Solve problems, verify your skills, and earn XP.