Simple Python  Solution | Prefix Sum | O(n) | O(1)
Intuition\n Describe your first thoughts on how to solve this problem. \nElements are in sorted order and we want to calculate absolute difference of a number w
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nElements are in sorted order and we want to calculate absolute difference of a number with other numbers.\nFor each element nums[i], we want to calculate the sum of absolute differences between nums[i] and all other elements.\nTo efficiently calculate this sum, we can break it down into two parts:\nThe sum of differences for elements to the left of nums[i].\nThe sum of differences for elements to the right of nums[i].\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Calculate the total sum of the array, total_sum.\n2. Initialize a result array, res, with the same length as the input array nums.\n3. Iterate through each element in the array using a for loop.\n4. For each element at index i, calculate the sum of absolute differences between nums[i] and all other elements.\n5. Update the res array with the calculated sum for the current index.\n    for each number num at index i, get sum of elements before number num and subtract it from num*i and get sum of elements after number n and subtract (len(nums)-i-1)*n from it.\n6. Return the res array.\n\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def getSumAbsoluteDifferences(self, nums: List[int]) -> List[int]:\n        sum_val=0\n        total_sum = sum(nums)\n        res = [0] * len(nums)\n        n = len(nums)\n        for i, num in enumerate(nums):\n            if i==0:\n                res[i] = (total_sum - (num*n))\n            else:\n                res[i] = ((num*i) - (sum_val)) + (total_sum - (sum_val + num) - (num*(n-i-1)))\n            sum_val += num\n        return res\n```
['Prefix Sum', 'Python3']