Find the minimum possible health of the winning player | Java implementation of the above approach ; Function to return the minimum possible health of the last player ; Find the GCD of the array elements ; Driver code
class GFG { static int minHealth ( int health [ ] , int n ) { int gcd = 0 ; for ( int i = 0 ; i < n ; i ++ ) { gcd = __gcd ( gcd , health [ i ] ) ; } return gcd ; } static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } public static void main ( String [ ] args ) { int health [ ] = { 5 , 6 , 1 , 2 , 3 , 4 } ; int n = health . length ; System . out . println ( minHealth ( health , n ) ) ; } }