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