Maximum number of 0 s placed consecutively at the start and end in any rotation of a Binary String | Function to find the maximum sum of consecutive 0 s present at the start and end of a string present in any of the rotations of the given string ; Check if all the characters in the string are 0 ; Iterate over characters of the string ; If the frequency of '1' is 0 ; Print n as the result ; Concatenate the string with itself ; Stores the required result ; Generate all rotations of the string ; Store the number of consecutive 0 s at the start and end of the string ; Count 0 s present at the start ; Count 0 s present at the end ; Calculate the sum ; Update the overall maximum sum ; Print the result ; Given string ; Store the size of the string
function findMaximumZeros ( str , n ) { var c0 = 0 ; var i ; for ( i = 0 ; i < n ; ++ i ) { if ( str [ i ] == ' ' ) c0 ++ ; } if ( c0 == n ) { document . write ( n ) ; return ; } var s = str + str ; var mx = 0 ; var j ; for ( i = 0 ; i < n ; ++ i ) { var cs = 0 ; var ce = 0 ; for ( j = i ; j < i + n ; ++ j ) { if ( s [ j ] == ' ' ) cs ++ ; else break ; } for ( j = i + n - 1 ; j >= i ; -- j ) { if ( s [ j ] == ' ' ) ce ++ ; else break ; } var val = cs + ce ; mx = Math . max ( val , mx ) ; } document . write ( mx ) ; } var s = " " ; var n = s . length ; findMaximumZeros ( s , n ) ;