Simple solution with Prefix Sum in Python3
Intuition\nHere we have:\n- nums as list of integers\n- our goal is to find sum of absolute differences in sorted array\n\nWe\'re going to use Prefix Sum to cal
# Intuition\nHere we have:\n- `nums` as list of integers\n- our goal is to find sum of absolute differences in sorted array\n\nWe\'re going to use **Prefix Sum** to calculate `left` and `right` parts (the first is for **positive** diff, and the last if for **negative**).\n\n# Approach\n1. declare and fill `prefix`\n2. iterate over `nums`\n3. calculate `left` and `right` sum parts\n4. append sum to the `ans` and return it\n\n# Complexity\n- Time complexity: **O(N)**\n\n- Space complexity: **O(N)**\n\n# Code\n```\nclass Solution:\n    def getSumAbsoluteDifferences(self, nums: List[int]) -> List[int]:\n        prefix = [nums[0]]\n        n = len(nums)\n\n        for i in range(1, n): prefix.append(prefix[i - 1] + nums[i])\n\n        ans = []\n        \n        for i in range(len(nums)):\n            left = nums[i] * (i + 1) - prefix[i]\n            right = prefix[-1] - prefix[i] - nums[i] * (n - i - 1)\n            ans.append(left + right)\n\n        return ans \n```
['Array', 'Prefix Sum', 'Python3']