TC O(n) using prefix sum
\nclass Solution {\npublic:\n    vector<int> getSumAbsoluteDifferences(vector<int>& nums) \n    {\n        \n        int sum =0, pref =0, n = nums.size();\n    
```\nclass Solution {\npublic:\n    vector<int> getSumAbsoluteDifferences(vector<int>& nums) \n    {\n        \n        int sum =0, pref =0, n = nums.size();\n        \n        \n        vector<int> ans(n,0);\n        \n        \n        for(auto it: nums)\n        {\n            sum += it;\n        }\n\n        \n        \n        for(int i=0; i<n; ++i)\n        {\n        \n\t\t// ans at i:     from left      + from element at nums[i]      +    from right side\n\t\t\t\n            ans[i] = (i*nums[i] - pref) +     (nums[i] - nums[i])       + ((sum - pref - nums[i]) -  (n-i-1)*nums[i] );\n            \n            \n            pref += nums[i];\n        \n        }\n        \n        return ans;\n    }\n};\n```
['C', 'Prefix Sum', 'C++']