Check if all 3 Candy bags can be emptied by removing 2 candies from any one bag and 1 from the other two repeatedly | Python code for the above approach ; If total candies are not multiple of 4 then its not possible to be left with 0 candies ; If minimum candies of three bags are less than number of operations required then the task is not possible ; Driver code
def can_empty ( a , b , c ) : NEW_LINE INDENT if ( ( a + b + c ) % 4 != 0 ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT else : NEW_LINE INDENT m = min ( a , min ( b , c ) ) ; NEW_LINE if ( m < ( a + b + c ) // 4 ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT DEDENT return True ; NEW_LINE DEDENT a = 4 NEW_LINE b = 2 NEW_LINE c = 2 NEW_LINE print ( " true " if can_empty ( a , b , c ) else " false " ) ; NEW_LINE a = 3 NEW_LINE b = 4 NEW_LINE c = 2 NEW_LINE print ( " true " if can_empty ( a , b , c ) else " false " ) ; NEW_LINE