educative.io

Why don't we have `if (dp[i - 1][s])` condition just like in subset sum

In Subset sum we have

      if (dp[i - 1][s]) {
        dp[i][s] = dp[i - 1][s];

But here we are just doing

        dp[i][s] = dp[i - 1][s];

Was if unnecessary earlier?

Thanks

Actually, each value of dp is either a positive number or 0, you don’t need to check it again. while there is a different situation in subset-sum problem, because the value is boolean, so it’s mandated.