Coin Change
Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Bloomberg reported this Coin Change OA in February 2021, and the constraint that matters is amount up to 10000 with unlimited coins. Brute force over every combination explodes fast, so trying all coin sequences won't finish. It's a classic dynamic programming problem: minimum coins to hit an exact amount, or -1 if you can't. If you've seen it, it's a ten-minute job. If you blank on the recurrence, you burn the clock fast. StealthCoder sits invisibly on your screen during the live OA as a safety net if your mind goes empty. Know the shape before you open the assessment.
The problem
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) → int Examples Example 1 coins = [1,2,5] amount = 11 return = 3 Two coins of denomination 5 and one coin of denomination 1 make 11 with three coins. Example 2 coins = [2] amount = 3 return = -1 No number of coins with denomination 2 can make the odd amount 3. Example 3 coins = [1] amount = 0 return = 0 The empty selection makes amount 0. Constraints 1 <= coins.length <= 12. 1 <= coins[i] <= 2^31 - 1. All denominations are distinct. 0 <= amount <= 10000.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is a 1D DP array of size amount + 1. Set dp[0] = 0 and everything else to infinity (or amount + 1). For each amount i from 1 to amount, try every coin c where c <= i and set dp[i] = min(dp[i], dp[i - c] + 1). Return -1 if dp[amount] is still infinity. That's O(amount * coins), roughly 120000 operations at worst, which is nothing. The pitfall is greedy. Taking the largest coin first fails on cases like [1,3,4] with amount 6. Another trap: coins[i] can reach 2^31 - 1, so check c <= i before indexing, and watch overflow if you use a huge sentinel plus one. Handle amount 0 returning 0. If you freeze on the recurrence mid-assessment, StealthCoder is the hedge that gives you the working solution while you keep typing.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Coin Change cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as coin change. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Bloomberg's OA.
Bloomberg reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Coin Change FAQ
How hard is Bloomberg's Coin Change really?+
Medium difficulty, but it's a very standard DP problem. The code is about ten lines once you see the recurrence. The hard part is recognizing that greedy fails and that you need a table of best answers for every smaller amount.
What's the trick to solve it?+
Build dp where dp[i] is the fewest coins to make i. Start dp[0] as 0, others as a large sentinel. For each i, loop through coins and take the min of dp[i - coin] + 1. If the final value is still the sentinel, return -1.
Why doesn't greedy work here?+
Taking the biggest coin first can miss the optimal answer. With coins [1,3,4] and amount 6, greedy picks 4+1+1 for three coins, but 3+3 uses two. Denominations aren't guaranteed to be canonical, so you need DP.
What edge cases should I test?+
Test amount 0, which returns 0. Test an impossible case like coins [2] and amount 3, which returns -1. Test a coin larger than the amount, and a single coin of 1. Guard with coin <= i so large denominations up to 2^31 - 1 never index out of range.
How do I prepare in 48 hours?+
Write the bottom-up DP from memory twice, then do the top-down memoized version once. Run your code on the three examples plus the greedy-breaking case. Then do a few related DP problems like coin combinations or climbing stairs so the recurrence feels automatic.