Classic unbounded knapsack / coin change in disguise.
Recognize this as the classic coin change problem (minimum coins) and solve it using dynamic programming. Define dp[i] as the minimum number of canisters to make amount i, initialize dp[0]=0 and others to infinity, then iterate amounts from 1 to target, updating dp[i] = min(dp[i], dp[i - capacity] + 1) for each capacity. Return dp[target] if finite, else -1.
Pro tip: After presenting the DP solution, mention that BFS on the amount graph is an alternative with the same O(target * n) time but can be more intuitive for finding the minimum number of steps. Also, briefly discuss edge cases like target=0 (return 0) and capacities larger than target (ignore them).
Confirm that canisters can be reused unlimited times, order doesn't matter, and we need the exact target. Ask about constraints (e.g., target size, number of capacities) to choose the right approach.
Let dp[i] be the minimum number of canisters needed to make amount i. Initialize dp[0] = 0 and dp[i] = infinity for i > 0.
For each amount i from 1 to target, iterate over each capacity c. If i >= c and dp[i - c] is not infinity, update dp[i] = min(dp[i], dp[i - c] + 1).
After filling the table, if dp[target] is still infinity, return -1; otherwise return dp[target].
State time complexity O(target * n) and space O(target). Mention edge cases: target=0 returns 0, capacities > target are ignored, and impossible cases return -1.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.