[C++ | Java | Python | JavaScript] Clean Code - O(N) Time - O(1) Space
C++\n\nvector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n    const int N = nums.size();\n    vector<int> ans(N, 0);\n    ans[0] = accumulate(nums.begi
**C++**\n```\nvector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n    const int N = nums.size();\n    vector<int> ans(N, 0);\n    ans[0] = accumulate(nums.begin(), nums.end(), 0) - (N * nums[0]);\n    for (int i = 1; i < N; i++)\n        ans[i] = ans[i - 1] + (nums[i] - nums[i - 1]) * i - (nums[i] - nums[i - 1]) * (N - i); \n    return ans;\n}\n```\n\n**Java:**\n```\npublic int[] getSumAbsoluteDifferences(int[] nums) {\n    int N = nums.length;\n    int[] ans = new int[N];\n    ans[0] = IntStream.of(nums).sum() - (N * nums[0]);\n    for (int i = 1; i < N; i++)\n        ans[i] = ans[i - 1] + (nums[i] - nums[i - 1]) * i - (nums[i] - nums[i - 1]) * (N - i); \n    return ans;\n}\n```\n\n**Python:**\n```\ndef getSumAbsoluteDifferences(self, nums: List[int]) -> List[int]:\n    N = len(nums);\n    ans = [0 for _ in range(N)]\n    ans[0] = sum(nums) - (N * nums[0]);\n    for i in range(1, N):\n        ans[i] = ans[i - 1] + (nums[i] - nums[i - 1]) * i - (nums[i] - nums[i - 1]) * (N - i); \n    return ans;\n```\n\t\n**JavaScript:**\n```\nvar getSumAbsoluteDifferences = function(nums) {\n    const N = nums.length;\n    const ans = new Array(N);\n    ans[0] = nums.reduce((a, b) => a + b, 0) - (N * nums[0]);\n    for (let i = 1; i < N; i++)\n        ans[i] = ans[i - 1] + (nums[i] - nums[i - 1]) * i - (nums[i] - nums[i - 1]) * (N - i); \n    return ans;\n};\n```
['C', 'Python', 'C++', 'Java', 'JavaScript']