C++ | O(N) Solution
Approach\nRearrange the equation\n\n# Complexity\n- Time complexity: O(N)\n\n- Space complexity: O(N)\n\n# Code\n\nclass Solution {\npublic:\n    vector<int> ge
# Approach\nRearrange the equation\n\n# Complexity\n- Time complexity: O(N)\n\n- Space complexity: O(N)\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n        vector<int> ans;\n        int n = nums.size();\n        int sum = 0;\n        for(auto x : nums) sum += x;\n        int prevSum = 0;\n\n        for(int i = 0; i < n; i++) {\n            int s = sum - (nums[i] * (n - i));\n            s += (nums[i] * i - prevSum);\n            ans.push_back(s);\n            sum -= nums[i];\n            prevSum += nums[i];\n        }\n\n        return ans;\n    }\n};\n```
['C++']