Coin Change

Medium Solved

Description

You are given an integer array coins representing different coin denominations and an integer amount.

Return the minimum number of coins needed to make up that amount. If it is not possible, return -1.

Input format / Clarification:

  • Line 1: Coin denominations as JSON array
  • Line 2: Integer amount

Examples

Input:

[1,2,5] 11

Output: 3

Input:

[2] 3

Output: -1

Note:

Print a single integer as output.

No submissions yet.

Discuss dynamic programming, optimal substructure, and bottom-up approaches.

Test Cases