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 any rotation of the string str ; Stores the count of 0 s ; If the frequency of '1' is 0 ; Print n as the result ; Stores the required sum ; Find the maximum consecutive length of 0 s present in the string ; Update the overall maximum sum ; Find the number of 0 s present at the start and end of the string ; Update the count of 0 s at the start ; Update the count of 0 s at the end ; Update the maximum sum ; Print the result ; Given string ; Store the size of the string
function findMaximumZeros ( str , n ) { var c0 = 0 ; for ( var i = 0 ; i < n ; ++ i ) { if ( str [ i ] == ' ' ) c0 ++ ; } if ( c0 == n ) { document . write ( n ) ; return ; } var mx = 0 ; var cnt = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ' ' ) cnt ++ ; else { mx = Math . max ( mx , cnt ) ; cnt = 0 ; } } mx = Math . max ( mx , cnt ) ; var start = 0 , end = n - 1 ; cnt = 0 ; while ( str [ start ] != ' ' && start < n ) { cnt ++ ; start ++ ; } while ( str [ end ] != ' ' && end >= 0 ) { cnt ++ ; end -- ; } mx = Math . max ( mx , cnt ) ; document . write ( mx ) ; } var s = " " ; var n = s . length ; findMaximumZeros ( s , n ) ;