Diamensions in knapsack dp

usually knapsack problem dp[i][j] represent maximum profit we can make by taking i items with capacity j.Can I interchange those diamension such that dp[i][j] represent maximum profit with j items and i capacity?

@sahazeer123
yeah u can do that

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.