Self-Explanatory Code ||🏃‍♂️🏃‍♂️DRY RUN included ✅✅
Intuition\nSince, given array is in ascending order, for an element: \nNumbers on LEFT -- smaller\nNumbers on RIGHT -- larger\nand \n|a-x| = -(a-x) for a fixed 
# Intuition\nSince, given array is in ascending order, for an element: \nNumbers on LEFT -- smaller\nNumbers on RIGHT -- larger\nand \n***|a-x| = -(a-x)*** for a fixed a, if a<x\n***|a-x| = a - x***  for a fixed a, if a>x\n\nexample, \n|2-5| = -(2-5) = 3\n|3-2| = +(3-2) = 1\nTherefore, maintain a Prefix Sum Array\n### DRY RUN : : \n[2, 3, 5]\nprefi sum subarray : [0, 2, 5, 10]\n1. for i = 0, element 2\na. sum of numbers on left = 0\nb. sum of numbers on right(including self) = 10,\n        |2-2|+|2-3|+|2-5| = -(2-2)-(2-3)-(2-5) = (2+3+5)-(2+2+2)\n        i.e., ***sum of elements on right - number of elements * nums[i]***\n\n2. for i = 1, element 3\n    a. sum of numbers on left = 2\n    |3-2| = (3-2) = ***number of elements * nums[i] - sum of elements on left***\n    b. |3-3|+|3-5| = -(3-3)-(3-5) = (3+5)-(3*2) = 2\n    total = 2+1 = 3\n3. Similarly for 5\n    a. sum of numbers on left = 5\n    |5-2|+|5-3| = (5-2)+(5-3) = (5*2) - (5) = 5\n    b. |5-5| = -(5-5) = 0\n\n\n# Complexity\n- Time complexity: $$O(n)$$\n\n- Space complexity: $$O(n)$$\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n        int n = nums.size();\n        vector<int>prefix(n+1, 0); // prefix sum array\n        prefix[0]=0;\n        for(int i = 0;i<n;i++){\n            prefix[i+1] = prefix[i]+nums[i];\n        }\n        vector<int>res; // result vector\n        for(int i = 0;i<n;i++){\n            int greater = (prefix[n]-prefix[i])-(nums[i]*(n-i));\n            int smaller = (nums[i]*(i+1))-(prefix[i+1]-prefix[0]);\n            res.push_back(greater+smaller);\n        }\n        return res;\n    }\n};\n```
['Prefix Sum', 'C++']