Coin Change
Updated
Problem statement
You are given an array coins of distinct positive coin denominations and a nonnegative integer amount.
You have an unlimited supply of every denomination. Return the minimum number of coins needed to make exactly amount. If no combination can make the amount, return -1.
An amount of 0 requires 0 coins.
Function
coinChange(coins: int[], amount: int) → intExamples
Example 1
coins = [1,2,5]amount = 11return = 3Two coins of denomination 5 and one coin of denomination 1 make 11 with three coins.
Example 2
coins = [2]amount = 3return = -1No number of coins with denomination 2 can make the odd amount 3.
Example 3
coins = [1]amount = 0return = 0The empty selection makes amount 0.
Constraints
1 <= coins.length <= 12.1 <= coins[i] <= 2^31 - 1.- All denominations are distinct.
0 <= amount <= 10000.
More Pinterest Onsite Interview questions
- Minimum Bus Routes to a DestinationPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Delete and Compact a Forest SubtreePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Filter Pins by Excluded IDsONSITE INTERVIEW · Seen Oct 2026
- Top-Scoring Items in a Time WindowONSITE INTERVIEW · Seen Oct 2026
- Optimal Account BalancingPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Escape Room LeaderboardPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Policy Violation Set ChecksONSITE INTERVIEW · Seen Sep 2026
- Shortest Sequence of Source SubsequencesONSITE INTERVIEW · Seen Sep 2026
- Insert Addition and Multiplication OperatorsONSITE INTERVIEW · Seen Sep 2026
- Unique Active Pins by Time SegmentONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Coin ChangeMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Coin ChangeKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
- Coin ChangeBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Minimum Jumps with Parity-Restricted Jump LengthsGoogle · ONSITE INTERVIEWGoogle interview questions
- Path Through an O/X Grid Using Only Right and DownAmazon · PHONE SCREEN
- Fewest Jumps to the End or StuckAdobe · PHONE SCREENAdobe interview questions
- Coin ChangeGrubhub · PHONE SCREENGrubhub interview questions
- Largest Diamond of Ones in a GridRippling · PHONE SCREENRippling interview questions
- Maximum Sum with K-Element SkippingPhonePe · ONSITE INTERVIEWPhonePe interview questions
- Number of IslandsFleetx · ONSITE INTERVIEW