Java O(n)
Time: O(N)\n\npublic int maxProductDifference(int[] nums) {\n\tint largest = 0, secondLargest = 0, smallest = Integer.MAX_VALUE, secondSmallest = Integer.MAX_VA
Time: O(N)\n```\npublic int maxProductDifference(int[] nums) {\n\tint largest = 0, secondLargest = 0, smallest = Integer.MAX_VALUE, secondSmallest = Integer.MAX_VALUE;\n\tfor(int i=0;i<nums.length;i++) {\n\t\tif(nums[i]>=largest) {\n\t\t\tsecondLargest = largest;\n\t\t\tlargest = nums[i];\n\t\t} else if(nums[i]>secondLargest) secondLargest = nums[i];\n\t\tif(nums[i]<=smallest) {\n\t\t\tsecondSmallest = smallest;\n\t\t\tsmallest = nums[i];\n\t\t} else if(nums[i]<secondSmallest) secondSmallest = nums[i];\n\t}\n\treturn largest * secondLargest - smallest * secondSmallest;\n}\n```\n\nAnother solution\n with time: O(NLogN)\n```\npublic int maxProductDifference(int[] nums) {\n\tArrays.sort(nums);\n\treturn nums[nums.length-1] * nums[nums.length-2] - nums[0]*nums[1];\n}\n```
[]