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