Two Approach-Without Product and With Product||C++, Beats 100%
Intuition\nFirst Approach-01:\nIn this we create a signFunc as stated in the question \nThen We simply do the product of all elements in vector and then pass it
# Intuition\nFirst Approach-01:\nIn this we create a `signFunc` as stated in the question \nThen We simply do the product of all elements in vector and then pass it to the `signFunc` \nMain trick to this Question is **Modulo operator**\nAs the product will exceed the int or long long Range so to overcome that we have to use a number to limit the product and to limit a number so that it dont cross a specific range we use Modulo operator \n\nThe task is to determine which number we can take as the upper limit\nSo for that we will go for 1e9+7 (i.e. 1000000007) as it is the highest prime number close to the range of int data type.\n*P.S. you can google it to know more about it *\n\nSecond Approach-02:(**Easy and Brainer way**)\nIn this method we are counting the no. of negative elements and if we found a zero we will return the 0\n\nif we dont then we simply check the count of negative number,\nif count is multiple of two then the resultant product will always be a positive number \nelse it will be a negative number\n\n\n\n# Approach-01-Code\n```\nclass Solution {\npublic:\n    int signFunc(long long product){\n        if(product < 0){\n            return -1;\n        }\n        else if(product > 0){\n            return 1;\n        }\n        else{\n            return 0;\n        }\n    }\n    int arraySign(vector<int>& n) {\n        long long int product=1;\n\n        for(auto val:n){\n            product *= val*1ll;\n            product = product%1000000007 ;\n        }\n\n        return signFunc(product);\n    }\n};\n```\n# Approach-02-Code\n```\nclass Solution {\npublic:\n    int arraySign(vector<int>& n) {\n        int count=0;\n        \n        for(auto val:n){\n            if(val<0){\n                count++;\n            }\n            else if(val==0){\n                return 0;\n            }\n        }\n\n        if(count&1){//condition to check a number is odd\n            return -1;\n        }\n        return 1;\n    }\n};\n```
['Array', 'Math', 'C++']