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 ( let i = start ; i < N ; ++ i ) { if ( str [ i ] == ' ' ) { ones ++ ; } else { zeroes ++ ; } if ( ones * zeroes > ans ) { break ; } let temp = solveUtil ( i + 1 , bucket + 1 , str , K ) ;