public class Solution {
    public double maxProduct(double[] arr) {
        double min = arr[0];
        double max = arr[0];
        double ans = arr[0];
        for (int i = 1; i < arr.length; i++) {
            double mx = max;
            double mn = min;
            min = Math.min(Math.min(arr[i], mx * arr[i]), mn * arr[i]);
            max = Math.max(Math.max(arr[i], mn * arr[i]), mx * arr[i]);
            ans = Math.max(max, ans);
        }
        return ans;
    }
}