Start filling zeroes and ones which to be accommodated in jth bucket then ans for current arrangement will be ones * zeroes + recur ( i + 1 , bucket + 1 )
for i in range ( start , N ) : NEW_LINE INDENT if ( str1 [ i ] == '1' ) : NEW_LINE INDENT ones += 1 NEW_LINE DEDENT else : NEW_LINE INDENT zeroes += 1 NEW_LINE DEDENT if ( ones * zeroes > ans ) : NEW_LINE INDENT break NEW_LINE DEDENT temp = solveUtil ( i + 1 , bucket + 1 , str1 , K , dp ) NEW_LINE DEDENT