Easy C++ solution, O(n) time complexiety
Intuition & Approach\nHere we subtract same numbers for all the elements we only have to take care of the negative difference, as the given array is ordered so 
# Intuition & Approach\nHere we subtract same numbers for all the elements we only have to take care of the negative difference, as the given array is ordered so will be the difference.\nHere is the example to better understand the code\nFirst calculate the result for n[0],we get ans[0]=24 (example case: 1,4,6,8,10)\nFor the next element n[1]=4, find the difference between the current element and last element i.e. 4-1=3,\nnow no. of elements before n[1] is 1 (we will add 1*3 as 4-1 is positive) and after n[1] is 4 (including n[1]) so we will subtract 4 * 3 as 4-4, 4-6, 4-8, 4-10 are non positive.\nans[1]=ans[0]+(n[0] - n[1])(1) - (n[i] - n[1])(4)\nans[1]=24 + 3 * 1 - 3 * 4\nans[1]=15\nsimilarly ans[2]= 15 + (6-4)(2) - (6-4)(3)= 13\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> getSumAbsoluteDifferences(vector<int>& n) {\n        vector<int> ans(n.size(),0);\n        int ns=n.size();\n        for(int i=0; i<1;i++){\n            int temp=0;\n            for(int j=0; j<ns; j++){\n                temp=temp+abs(n[i]-n[j]);\n            }\n            ans[0]=temp;;\n        }\n        for(int i=1;i<ns;i++){\n            ans[i]=ans[i-1]+(n[i]-n[i-1])*i-(n[i]-n[i-1])*(ns-i);\n        }\n        return ans;\n    }\n};\n```
['Math', 'C++']