C++ O(N) || 2 Pass
Connect with me on LinkedIn: https://www.linkedin.com/in/abhay5349singh/\n\nApproach:\n\n1. Considering Left --> Right movement\n let i=number of element to lef
**Connect with me on LinkedIn**: https://www.linkedin.com/in/abhay5349singh/\n\n**Approach:**\n\n1. Considering Left --> Right movement\n* let i=number of element to left of current\n* since the array is sorted, increment in current difference will be i*(a[i]-a[i-1])\n\n2.Considering Right --> Left movement\n* let (n-i-1)=number of element to right of current\n* since the array is sorted, increment in current difference will be (n-i-1)*(a[i+1]-a[i]) \n\n```\nclass Solution {\npublic:\n\n    vector<int> getSumAbsoluteDifferences(vector<int>& a) {\n        int n=a.size();\n        \n        vector<int> left(n,0);\n        for(int i=1;i<n;i++) left[i]=left[i-1]+(a[i]-a[i-1])*i;\n        \n        vector<int> right(n,0);\n        for(int i=n-2;i>=0;i--) right[i]=right[i+1]+(a[i+1]-a[i])*(n-i-1);\n        \n        vector<int> ans(n);\n        for(int i=0;i<n;i++) ans[i]=left[i]+right[i];\n        \n        return ans;\n    }\n};\n```\n\n**Do Upvote if it helps!**
['C++']