Save 25%Black Friday: 25% off all plans — use code BLACKFRIDAY2026 at checkout. Ends Friday, Dec 4.Claim the deal

You are given an array of coin denominations and an integer max, and you are asked to form every integer amount from 1 up to max using these coins.

Find the minimal number of coins used while still being able to create every value in the range [1, max]. Return -1 if these coin denominations cannot form any amount in that range.

Test Cases
Input
Output
Expected