Find the minimum possible health of the winning player | C ++ implementation of the approach ; Function to return the minimum possible health of the last player ; Find the GCD of the array elements ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int minHealth ( int health [ ] , int n ) { int gcd = 0 ; for ( int i = 0 ; i < n ; i ++ ) { gcd = __gcd ( gcd , health [ i ] ) ; } return gcd ; } int main ( ) { int health [ ] = { 5 , 6 , 1 , 2 , 3 , 4 } ; int n = sizeof ( health ) / sizeof ( int ) ; cout << minHealth ( health , n ) ; return 0 ; }