Beats 100% of users with C++ || Step By Step Explain || Easy to Understand ||
Abhiraj Pratap Singh\n\n---\n\n# if you like the solution please UPVOTE it....\n\n---\n\n# Intuition\n Describe your first thoughts on how to solve this problem
# Abhiraj Pratap Singh\n\n---\n\n# if you like the solution please UPVOTE it....\n\n---\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- The problem requires determining the sign of the product of all elements in the array.\n- Negative numbers in the array will affect the sign of the product.\n- Zero in the array will result in a product of zero.\n\n\n![Screenshot (47).png](https://assets.leetcode.com/users/images/636d5c23-afd6-4095-b9de-31bfe7f72a27_1710256766.7929735.png)\n\n---\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- Iterate through the array and count the number of negative numbers encountered.\n- If a zero is encountered, return 0 immediately.\n- If the count of negative numbers is even, return 1 for a positive product; otherwise, return -1 for a negative product.\n\n---\n\n# Complexty \n\n- **Time complexity :** O(n), where n is the size of the input array nums. We iterate through the array once.\n- **Space complexity :** O(1), as we use a constant amount of extra space for variables to store counts.\n\n---\n\n# Code\n```\nclass Solution {\npublic:\n    int arraySign(vector<int>& nums) \n    {\n        int negative_number=0;\n        int zero=0;\n        for(int i=0;i<nums.size();i++)\n        {\n            if(nums[i]==0)\n                return 0;\n            else if(nums[i]<0)\n                negative_number++;\n        }\n        if(negative_number %2 == 0)\n            return 1;\n        return -1;\n    }\n};\n```\n---\n\n# if you like the solution please UPVOTE it....\n\n---\n\n\n![discord-discordgifemoji.gif](https://assets.leetcode.com/users/images/a494df67-5d0d-477b-9eb5-37a41c096c0e_1710256689.4648082.gif)\n![fucking-die-redditor-stupid-cuck-funny-cat.gif](https://assets.leetcode.com/users/images/05a8c4b3-6111-4aab-9913-5b54ce791a56_1710256691.9424775.gif)\n\n\n---\n---
['Array', 'Math', 'C++']