Easiest O(N) C++ Code (Highly Understandable)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nCalculate Total Sum (s):\n\ns = accumulate(a.begin(), a.end(), 0);: Use t
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nCalculate Total Sum (s):\n\ns = accumulate(a.begin(), a.end(), 0);: Use the accumulate function from the <numeric> header to calculate the sum of all elements in the vector a and store it in the variable s.\nCalculate Absolute Differences:\n\nLoop through each element in the vector a using for(i = 0; i < n; i++).\nint x = (a[i] * (i) - c);: Calculate the sum of absolute differences for the left side of the current element.\nint y = (s - c) - a[i] * (n - i);: Calculate the sum of absolute differences for the right side of the current element.\nans.push_back(x + y);: Add the total sum of absolute differences for the current element to the ans vector.\nc += a[i];: Update the cumulative sum c by adding the current element.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> getSumAbsoluteDifferences(vector<int>& a) {\n        vector<int>ans;\n        int i,c=0,s=0,n=a.size();\n\n        s = accumulate(a.begin(),a.end(),0);\n\n        for(i=0;i<n;i++){\n            int x = (a[i]*(i)-c);\n            int y = (s-c) - a[i]*(n-i);\n            ans.push_back(x+y);\n            c+=a[i];\n        }\n\n        return ans;\n    }\n};\n```
['Array', 'Math', 'C++']