Java O(n) time, Two Pointer
the test case have some corner case, eg: product can exceed long.max. So need to take care of it.\nThe basic thinking is: \ngo through the array, mult each elme
the test case have some corner case, eg: product can exceed long.max. So need to take care of it.\nThe basic thinking is: \ngo through the array, mult each elment, \n    if meet 0, update pointer j because the previous subarray can not be used, meantime update product = 1.\n    else if product > 0, there is a valid candidate ans, update it with ans;\n\t\nBecause it could be like this:[-1, 2, 3, 4, 5], so we need to go through array from back to front again.\n\n```\nclass Solution {\n    int M = 1000_000_007;\n    public int getMaxLen(int[] nums) {\n        int ans = 0, n = nums.length;\n        long product = (long)1;\n        for(int i = 0, j = 0; i < n; i++) {\n            product *= nums[i];\n            if(product == 0) {\n                j = i + 1;\n                product = 1;\n                continue;\n            }\n            product %= M;\n            if(product > 0) {\n                ans = Math.max(ans, i - j + 1);\n            }\n        }\n\n        product = 1;\n        for(int i = n - 1, j = n - 1; i >= 0; i--) {\n            product *= nums[i];\n            if(product == 0) {\n                j = i - 1;\n                product = 1;\n                continue;\n            }\n            product %= M;\n            if(product > 0) {\n                ans = Math.max(ans, j - i + 1);\n            }\n        }\n        \n        return ans;\n    }\n}
['Java']