C++ 🔥 Easy approach 🔥 Explained 🔥
PLEASE UPVOTE \uD83D\uDC4D\n# Approach\n- ##### The problem asks us to determine the sign of the product of all the numbers in the given array. To solve this pr
# **PLEASE UPVOTE \uD83D\uDC4D**\n# Approach\n- ##### The problem asks us to determine the sign of the product of all the numbers in the given array. To solve this problem, we need to consider the following cases:\n    1. ##### If the product of all the numbers is positive, the sign is 1.\n    1. ##### If the product of all the numbers is negative, the sign is -1.\n    1. ##### If the product of all the numbers is zero, the sign is 0.\n- ##### To compute the product of all the numbers in the array, we can iterate over the array and count the total negative numbers. We can initialize the cnt as 0 and then update it at each step of the iteration.\n- ##### At any index, if number is 0, simply return 0.\n- ##### Once we have computed the product, we can determine the sign of the product using an if-else statement. If the cnt is odd, the sign is -1. If the cnt is even, the sign is 1.\n\n- ##### Therefore, we can write a function that takes an array as input, computes the count of negative numbers in the array, and returns the sign of the product.\n\n# Complexity\n- Time complexity:O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# **PLEASE UPVOTE \uD83D\uDC4D**\n# Code\n```\nclass Solution {\npublic:\n    int arraySign(vector<int>& a) {\n        int cnt = 0;\n        for(int i = 0; i < a.size(); i++) \n        {\n            if(a[i] == 0) return 0;\n            if(a[i] < 0) cnt++;\n        }\n        return cnt%2 ? -1 : 1;\n    }\n};\n```\n\n![e2515d84-99cf-4499-80fb-fe458e1bbae2_1678932606.8004954.png](https://assets.leetcode.com/users/images/e5cc6438-63d7-47fb-84d1-e4e36cf43c6e_1683003574.1370602.png)\n
['Math', 'C++']