Grokking Dynamic Programming Patterns for Coding Interviews
Ask Author
Back to course home

0% completed

Vote For New Content
In the bottom up approach, why is the code checking this (dp[i][t-ribbonLengths[...

UndergroundSkye

Nov 30, 2022

In the bottom up approach, why is the code checking this (dp[i][t-ribbonLengths[i]] != Integer.MIN_VALUE), taken from the below Java if statement?

if(t >= ribbonLengths[i] && dp[i][t-ribbonLengths[i]] != Integer.MIN_VALUE) dp[i][t] = Math.max(dp[i][t], dp[i][t-ribbonLengths[i]]+1);

This seems like it would only be necessary if there was a constraint saying you need to use the entire ribbon. But since we do not have that constraint this would cause this solution to fail in certain cases.

0

0

Comments
Comments

On this page