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 ; Driver Code ; Given string ; Store the size of the string
def findMaximumZeros ( st , n ) : NEW_LINE INDENT c0 = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( st [ i ] == '0' ) : NEW_LINE INDENT c0 += 1 NEW_LINE DEDENT DEDENT if ( c0 == n ) : NEW_LINE INDENT print ( n ) NEW_LINE return NEW_LINE DEDENT s = st + st NEW_LINE mx = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT cs = 0 NEW_LINE ce = 0 NEW_LINE for j in range ( i , i + n ) : NEW_LINE INDENT if ( s [ j ] == '0' ) : NEW_LINE INDENT cs += 1 NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT for j in range ( i + n - 1 , i - 1 , - 1 ) : NEW_LINE INDENT if ( s [ j ] == '0' ) : NEW_LINE INDENT ce += 1 NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT val = cs + ce NEW_LINE mx = max ( val , mx ) NEW_LINE DEDENT print ( mx ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT s = "1001" NEW_LINE n = len ( s ) NEW_LINE findMaximumZeros ( s , n ) NEW_LINE DEDENT