Fully Explained Java Solution ✅
Intuition\n Describe your first thoughts on how to solve this problem. \nWe will maintain a counter to calculate the negative values in the array.\nIf the count
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe will maintain a counter to calculate the negative values in the array.\nIf the counter got the even value after traversing the whole array, it means the product of all array elements will be positive.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nTraverse the array, \nIf any element in the array appears to be 0, simply return 0;\nIf we encounter any negative value then we will increase our negativeCount by 1;\n\nWe dont have to deal with positive values as positive*positive is always positive.\n\nIn the last we will check if negativeCount is even or not, if its even, then product will be positive, else it will be negative.\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int arraySign(int[] nums) {\n        //counter to keep track of negative values\n        int negativeCount = 0;\n        //Traversing the loop\n        for(int i=0; i<nums.length; i++) {\n            //If any array element is 0, product will be zero\n            if(nums[i] == 0) {\n                return 0;\n            }\n            //If negative number, then increase the negativeCount by 1\n            if(nums[i] < 0) {\n                negativeCount++;\n            }\n        }\n        //If negativeCount is even, product will be positive, hence return 1\n        if(negativeCount%2 == 0) {\n            return 1;\n        } else {    //negativeCount is odd, product will be negative\n            return -1; \n        }\n    }\n}\n```
['Array', 'Java']