Easy to Understand and Implement C++ Solution
Intuition: why idea of finding product does not work:\nConsider this code:\n\nint arraySign(vector<int>& nums) {\n        int p = 1;\n        for(auto x: nums)\
**Intuition: why idea of finding product does not work:**\nConsider this code:\n```\nint arraySign(vector<int>& nums) {\n        int p = 1;\n        for(auto x: nums)\n            p *= x;\n        if(p > 0)\n            return 1;\n        else if(p < 0)\n            return -1;\n        return 0;\n    }\n```\nThis code passes successfully for small test cases where the input is small. Larger size of array can lead to Runtime Error:\n```\nRuntime Error Message:\nLine 6: Char 15: runtime error: signed integer overflow: 688764384 * -77 cannot be represented in type \'int\' (solution.cpp)\nSUMMARY: UndefinedBehaviorSanitizer: undefined-behavior prog_joined.cpp:15:15\nLast executed input:\n[9,72,34,29,-49,-22,-77,-17,-66,-75,-44,-30,-24]\n```\n\nSo a better solution would be to check if any of the element in the array is a zero. If yes, then return 0, If no, then count how many negative numbers are there. If their count is even, then return 1, else return 0.\n\n**Code for the same:**\n```\nint arraySign(vector<int>& nums) {\n        int countNeg = 0;\n        for(auto x: nums){\n            if(x < 0)\n                countNeg++;\n            else if(x == 0)\n                return 0;\n        }\n        if(countNeg%2 ==0)\n            return 1;\n        return -1;\n    }\n```\n**Time complexity: O(N)\nSpace Complexity: O(1)**\n\nDo upvote this solution if it helped you. \nPeace :)
['C', 'C++']