Maximize count of empty water bottles from N filled bottles | Function to find the maximum bottles that can be emptied ; Iterate until a is non - zero ; Add the number of bottles that are emptied ; Update a after exchanging empty bottles ; Stores the number of bottles left after the exchange ; Return the answer ; Driver Code ; Function call
def maxBottles ( n , e ) : NEW_LINE INDENT s = 0 NEW_LINE b = 0 NEW_LINE a = n NEW_LINE while ( a != 0 ) : NEW_LINE INDENT s = s + a NEW_LINE a = ( a + b ) // e NEW_LINE b = n - ( a * e ) NEW_LINE n = a + b NEW_LINE DEDENT return s NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 9 NEW_LINE e = 3 NEW_LINE s = maxBottles ( n , e ) NEW_LINE print ( s ) NEW_LINE DEDENT