Loading your feed…
When an interviewer gives you a DP problem, jumping straight into a 2D table usually causes brain-freeze. Use this 4-step framework out loud:
i, remaining capacity w). Those variables define your DP state: dp(i, w).dp(i + 1, w)val[i] + dp(i + 1, w - wt[i]) (if wt[i] <= w)max(Choice A, Choice B)dp[i] only depends on dp[i-1], allowing you to reduce $O(N \times W)$ space to a single $O(W)$ 1D array.Interviewers award 80% of marks for explaining Step 1 and Step 2 cleanly.
Answers, step-by-step code solutions, and community discussions are reserved for verified members. Create your free account in 30 seconds to unlock answers, ask follow-up questions, and connect with peers.