Kotlin solution
Complexity\n\n- Time complexity: O(n)\n- Space complexity: O(n)\n\n# Code\n\n\nclass Solution {\n    fun getSumAbsoluteDifferences(nums: IntArray): IntArray {\n
# Complexity\n\n- Time complexity: $$O(n)$$\n- Space complexity: $$O(n)$$\n\n# Code\n\n```\nclass Solution {\n    fun getSumAbsoluteDifferences(nums: IntArray): IntArray {\n        val prefix = nums.fold(mutableListOf<Int>()) { list, it ->\n            list += (list.lastOrNull() ?: 0) + it\n            list\n        }\n\n        return IntArray(nums.size) { i ->\n            i * nums[i] - (prefix[i] - nums[i]) +\n                prefix.last() - prefix[i] -\n                (nums.size - 1 - i) * nums[i]\n        }\n    }\n}\n```
['Kotlin']