Java O(n) Solution
\nclass Solution {\n    public int maxProductDifference(int[] nums) {\n        int max1 = Integer.MIN_VALUE;\n        int max2 = Integer.MIN_VALUE;\n        \n 
```\nclass Solution {\n    public int maxProductDifference(int[] nums) {\n        int max1 = Integer.MIN_VALUE;\n        int max2 = Integer.MIN_VALUE;\n        \n        int min1 = Integer.MAX_VALUE;\n        int min2 = Integer.MAX_VALUE;\n        \n        for(int val : nums){\n            if(val > max1){\n                max2 = max1;\n                max1 = val;\n            } else if(val > max2){\n                max2 = val;\n            }\n            \n            if(val < min1){\n                min2 = min1;\n                min1 = val;\n            } else if(val < min2){\n                min2 = val;\n            }\n        }\n        \n        return (max1 * max2) - (min1 * min2);\n    }\n}\n```\n
['Java']