dp
with dimensions (m+1) x (n+1)
filled with zeros.s
in the input list strs
:
a. Count the number of 0's (zeroes
) and 1's (ones
) in s
.
b. Iterate over the DP array from dp[m][n]
to dp[zeroes][ones]
in reverse order:
i. Update dp[i][j]
to be the maximum of dp[i][j]
and 1 + dp[i - zeroes][j - ones]
.dp[m][n]
as the result, which represents the size of the largest subset.