CPP Solution
\n# Code\n\nclass Solution {\npublic:\n    vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n        int n=nums.size();\n        vector<int>result(n);
\n# Code\n```\nclass Solution {\npublic:\n    vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n        int n=nums.size();\n        vector<int>result(n);\n\n        vector<int>prefixSum(n);\n        prefixSum[0]=nums[0];\n        for(int i=1; i<n;i++)\n        {\n            prefixSum[i]=prefixSum[i-1]+nums[i];\n        }\n\n        vector<int>suffixSum(n);\n        suffixSum[n-1]=nums[n-1];\n        for(int i=n-2;i>=0;i--)\n        {\n            suffixSum[i]=suffixSum[i+1]+nums[i];\n        }\n        for (int i = 0; i < n; i++) {\n            int leftSum = i>0?prefixSum[i - 1]:0;\n            int rightSum = i<n-1?suffixSum[i + 1]:0;\n            result[i] = (nums[i] * i - leftSum) + (rightSum - nums[i] * (n - i - 1));\n        }\n        return result;\n    }\n};\n```
['Array', 'Math', 'Prefix Sum', 'C++']