Java | 2 Approaches | Do checkout
Do vote up if you like it :)\nTC : O(N)\n\nclass Solution {\n    public int maxProductDifference(int[] nums) {\n        int n = nums.length;\n        int min = 
**Do vote up if you like it :)**\nTC : O(N)\n```\nclass Solution {\n    public int maxProductDifference(int[] nums) {\n        int n = nums.length;\n        int min = Integer.MAX_VALUE;\n        int secmin = Integer.MAX_VALUE;\n        int max = Integer.MIN_VALUE;\n        int secmax = Integer.MIN_VALUE;\n        \n        for(int i = 0; i < n; i++) {\n            \n            //Checking for min and secmin\n            if(nums[i] < min) {              //item smaller than min, hence both min and secmin gets updated\n                secmin = min;\n                min = nums[i];\n            }\n            else if(nums[i] < secmin) {     //item greater than min but item smaller than secmin\n                secmin = nums[i];\n            }\n            \n            \n            //Checking for max and secmax\n            if(nums[i] > max) {             //item greater than max, hence both max and secmax gets updated\n                secmax = max;\n                max = nums[i];\n            }\n            else if(nums[i] > secmax) {     //item smaller than max but item greater than secmax\n                secmax = nums[i];\n            }\n        }    \n        return max * secmax - min * secmin; \n    }\n}\n```\n-------------------------------------------------------------\nTC : O(NlogN)\n```\nclass Solution {\n    public int maxProductDifference(int[] nums) {\n        int n = nums.length;\n        Arrays.sort(nums);\n        return nums[n - 1] * nums[n - 2] - nums[0] * nums[1]; \n    }\n}\n```\n-------------------------------------------------------------
[]