SIMPLE PREFIX SUM C++ SOLUTION
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\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>& nums){\n        int n = nums.size();\n        vector<int> prefixSum(n, 0);\n        vector<int> result(n, 0);\n        prefixSum[0] = nums[0];\n        for(int i = 1; i < n;i++){\n            prefixSum[i] = prefixSum[i - 1] + nums[i];\n        }\n        for(int i = 0; i < n; i++){\n            // Sum of absolute differences for elements before i\n            if(i > 0){\n                int sumBefore = prefixSum[i - 1];\n                result[i] += i * nums[i] - sumBefore;\n            }\n            // Sum of absolute differences for elements after i\n            if(i < n - 1){\n                int sumAfter = prefixSum[n - 1] - prefixSum[i];\n                result[i] += sumAfter - (n - i - 1) * nums[i];\n            }\n        }\n        return result;\n    }\n};\n```
['C++']