C++ | Prefix Sum
\nclass Solution {\npublic:\n    vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n        int tot = 0, sum = 0;\n        for(int i = 0; i < nums.size
```\nclass Solution {\npublic:\n    vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n        int tot = 0, sum = 0;\n        for(int i = 0; i < nums.size(); i++)\n            tot += nums[i];\n        for(int i = 0; i < nums.size(); i++){\n            tot -= nums[i];\n            sum += nums[i];\n            nums[i] = tot + nums[i] * (i + 1) - nums[i] * (nums.size() - i - 1) - sum;\n        }\n        return nums;   \n    }\n};\n```
['Prefix Sum']