[C++] Prefix/Postfix Sum
Intuition\n Describe your first thoughts on how to solve this problem. \n- The array is sorted in non-decreasing order\n- For the nums[i]\n  - all left numbers 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- The array is sorted in non-decreasing order\n- For the `nums[i]`\n  - all left numbers `nums[0], ..., nums[i - 1]` are smaller or equal to `nums[i]`\n  - all right numbers `nums[i + 1], ..., nums[n - 1]` are bigger or equal to `nums[i]`\n- So the absolute differences\n  - for the left is `(nums[i] - nums[0]) + ... + (nums[i] - nums[i - 1])`\n  - for the right is `(nums[i + 1] - nums[i]) + ... + (nums[n - 1] - nums[i])`\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(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    // time/space: O(n)/O(1)\n    vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n        const int n = nums.size();\n        int left = 0, right = accumulate(nums.begin(), nums.end(), 0);\n        vector<int> result(n);\n        for (int i = 0; i < n; i++) {\n            result[i] = (nums[i] * i - left) + (right - nums[i] * (n - i));\n            left += nums[i];\n            right -= nums[i];\n        }\n        return result;\n    }\n};\n```
['C++']