Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    Practice problems / Fewest coins

    Fewest coins

    Mediumdynamic programmingbfs

    Given coin types coins (unlimited of each) and an amount, return the fewest coins that add up to exactly the amount, or -1 if it's impossible.

    Example 1

    Input:  coins = [1,2,5], amount = 11
    Output: 3

    5 + 5 + 1.

    Example 2

    Input:  coins = [2], amount = 3
    Output: -1

    Example 3

    Input:  coins = [1], amount = 0
    Output: 0

    Constraints

    • 1 ≤ coins.length ≤ 12
    • 1 ≤ coins[i] ≤ 2³¹ − 1
    • 0 ≤ amount ≤ 10⁴

    Submit checks your solution against 9 tests, including hidden ones.

    /**
     * @param {int[]} coins
     * @param {int} amount
     * @return {int}
     */
    function coinChange(coins, amount) {
      
    }
    
    Sign in to run
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.