Solution with derivation and explaination
consider ax + by = 1\nAssuming integer solution exists then \n\nwe can take out the common divisor of a and b. \nThe gcf is the greatest common divisor of a and
consider ax + by = 1\nAssuming integer solution exists then \n\nwe can take out the common divisor of a and b. \nThe gcf is the greatest common divisor of a and b.\n\ntherefor ax + by = gcf(a,b) * ( (a/gcf) * x + (b/gcf) * y ) = 1\n\nsince gcf divides a we can rewrite a as a = gcf * a1 .. where a1 is some integer\nsimilarly b = gcf * b1.. where b1 is some integer\n\nso ax + by = gcf * ( a1 * x + b1 * y ) = 1\n\ndividing both sides by gcf we get\n\na1 * x + b1 * y = 1 / gcf\n\nNow LHS is a integer because (a1, b1, x, y ) are all integer values. and LHS = RHS. Therefore 1/gcf should also be an integer. This is only possible when gcf = 1. For all other values 1/gcf will not be an integer.\nAlso if (x,y) integer solutions don\'t exist the condition won\' t be valid.\n\nTherefor ax + by = 1 only if gcf(a,b) = 1\n\nFor n variables as given in the question similar logic can be used to take out gcf( a, b, c , d .... ) common from LHS and we get gcf(a,b,c,d ... ) = 1 as the condition.\n\nOne must realise that the subarray simply means taking the 0 as the multiplicative coefficients for number not included.\n\n```\nclass Solution {\npublic:\n    bool isGoodArray(vector<int>& nums) {\n        int gcd = nums[0];\n        for( auto e : nums ){\n            gcd = __gcd( gcd, e );\n        }\n        \n        return gcd == 1;\n    }\n};\n```
[]