Kotlin: Straightforward, no sorting.
Code\r\n\r\nclass Solution {\r\n    fun maxProductDifference(nums: IntArray): Int {\r\n        var largest = Int.MIN_VALUE\r\n        var secondLargest = Int.MI
# Code\r\n```\r\nclass Solution {\r\n    fun maxProductDifference(nums: IntArray): Int {\r\n        var largest = Int.MIN_VALUE\r\n        var secondLargest = Int.MIN_VALUE\r\n        var smallest = Int.MAX_VALUE\r\n        var secondSmallest = Int.MAX_VALUE\r\n\r\n        for (num in nums) {\r\n            if (num >= largest) {\r\n                secondLargest = largest\r\n                largest = num\r\n            } else if (num > secondLargest) {\r\n                secondLargest = num\r\n            }\r\n\r\n            if (num <= smallest) {\r\n                secondSmallest = smallest\r\n                smallest = num\r\n            } else if (num < secondSmallest) {\r\n                secondSmallest = num\r\n            }\r\n        }\r\n\r\n        return (largest * secondLargest) - (smallest * secondSmallest)\r\n    }\r\n}\r\n```
['Kotlin']