Check if two piles of coins can be emptied by repeatedly removing 2 coins from a pile and 1 coin from the other | Java program for above approach ; Function to check if two given piles can be emptied by repeatedly removing 2 coins from a pile and 1 coin from the other ; If maximum of A & B exceeds the twice of minimum of A & B ; Not possible to empty the piles ; If sum of both the coins is divisible by 3 , then print Yes ; Otherwise , print " No " ; Driver Code
import java . util . * ; class GFG { static void canBeEmptied ( int A , int B ) { if ( Math . max ( A , B ) > 2 * Math . min ( A , B ) ) { System . out . println ( " No " ) ; return ; } if ( ( A + B ) % 3 == 0 ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } public static void main ( String [ ] args ) { int A = 1 , B = 2 ; canBeEmptied ( A , B ) ; } }