Java 100% time and space, with solution explanation.
Let a[] be the array of values and b[] be the array of constants such that\nsigma( a[i]b[i] ) =1 for 0 <= i < n.\n\nThis is equivalent to solving gcd( a[0], a[1
Let a[] be the array of values and b[] be the array of constants such that\nsigma( a[i]*b[i] ) =1 for 0 <= i < n.\n\nThis is equivalent to solving gcd( a[0], a[1] )*Y + sigma( a[i]*b[i]) = 1 for 2 <= i < n for some constant Y.\n\nWe simply reduced the problem from N to N-1. You can apply this recursively to solve the problem.\n\n```\nclass Solution {\n    public boolean isGoodArray(int[] a) {\n        int ans=a[0];\n        for(int t : a){\n            if(ans==1) break;\n            ans = gcd(ans, t);\n        }\n        return ans==1 ? true: false;\n    }\n    \n    private int gcd( int a, int b) {\n        if( a < b) return gcd(b,a);\n        if( b == 0 ) return a;\n        return gcd(b,a%b);\n    }\n}\n```
[]