Mid
From PDF
Coding
C# Coding Interview
Coin Change Problem (Minimum Coins to Make?
Short answer: Amount) int CoinChange(int[] coins, int amount)
Example code
{
int[] dp = new int[amount + 1]; Array.Fill(dp, amount + 1); dp[0] = 0;
for (int i = 1; i <= amount; i++)
{
foreach (int coin in coins)
{
if (coin <= i)
dp[i] = Math.Min(dp[i], 1 + dp[i - coin]);
}
}
return dp[amount] > amount ? -1 : dp[amount];
} Explanation: Bottom-up DP: min coins needed for all amounts up to target. Follow on:
Real-world example (ShopNest)
In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png