As reported: Walmart Software Engineer III (Java backend) round 1 DSA (Sept 2025): Coin Change, built up from recursion to memoisation to tabulation and then optimised, with follow-ups; Course Schedule was the second question. Also asked in round 1 of a Walmart Senior Software Engineer hiring drive (Mar 2026), next to longest substring without repeating characters.
Given coin denominations coins (unlimited supply of each) and an amount, return the fewest coins needed to make exactly amount, or -1 if it cannot be made.
This is LeetCode 322 — Coin Change.
Example
coins = [1,2,5], amount = 11 -> 3 (5 + 5 + 1)
coins = [2], amount = 3 -> -1
coins = [1], amount = 0 -> 0
Constraints: 1 ≤ coins.length ≤ 12; 1 ≤ coins[i] ≤ 2^31 − 1; 0 ≤ amount ≤ 10^4.
Code runner format: one JSON value per line: coins, then amount. Implement coinChange(coins, amount); the harness prints the count.