Python simple O(n) solution(dp with explain)
prev_s: saves the sum of elements before index i\nafter_s: saves the sum of elements after index i\n\nNotice that nums is already sorted\n\nfor given example [1
prev_s: saves the sum of elements before index i\nafter_s: saves the sum of elements after index i\n\n**Notice that nums is already sorted**\n\nfor given example [1, 2, 3, 4, 5]\nthe sum before element 3(index 2) is 1 + 2 = 3\nsum after element 3 is 4 + 5 = 9\nthe absolute diff before it is abs(1 - 3) + abs(2 - 3) = abs(1 + 2 - 3 * 3) = 3\nafter is is abs(4 - 3) + abs(5 - 3) = abs(4 + 5 - 3 * 2) = 3\nThat is how we count the absolute difference for each element in the array.\n\n```\nclass Solution:\n    def getSumAbsoluteDifferences(self, nums: List[int]) -> List[int]:\n        n = len(nums)\n        prev_s = [0] * n\n        after_s = [0] * n\n        for i in range(1, n):\n            prev_s[i] = prev_s[i - 1] + nums[i - 1]\n        for i in range(n - 2, -1, -1):\n            after_s[i] = after_s[i + 1] + nums[i + 1]\n        ans = [0] * n\n        for i in range(n):\n            ans[i] = (after_s[i] - (n - i - 1) * nums[i]) + (i * nums[i] - prev_s[i])\n        return ans\n```
['Dynamic Programming', 'Python']