public int maxProduct(int[] A) {
            assert A.length != 0;
            int globalMax = A[0];
            int prevMax = A[0];
            int prevMin = A[0];
            for (int i = 1; i < A.length; i++) {
                int max;
                int min;
                if (A[i] > 0) {
                    max = Math.max(A[i], prevMax * A[i]);
                    min = Math.min(A[i], prevMin * A[i]);
                } else {
                    max = Math.max(A[i], prevMin * A[i]);
                    min = Math.min(A[i], prevMax * A[i]);
                }
                globalMax = Math.max(globalMax, max);
                prevMax = max;
                prevMin = min;
            }
            return globalMax;
        }