Beats 80% | JavaScript | C++
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:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```javascript []\n/**\n * @param {number[]} nums\n * @return {number[]}\n */\nvar getSumAbsoluteDifferences = function(nums) {\n    let sum = nums.reduce((a, b) => a+b, 0);\n    let prev = 0;\n    let res = [];\n    for(let i=0; i<nums.length; i++) {\n        res.push(sum - prev - ((nums.length - i)*nums[i]) + ((i*nums[i]) - prev));\n        prev += nums[i];\n    }\n    return res;\n};\n```\n```cpp []\nclass Solution {\npublic:\n    vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n        int sum = accumulate(nums.begin(), nums.end(), 0);\n        int prev = 0;\n        vector<int> res;\n        for(int i=0; i<nums.size(); i++) {\n            res.push_back(sum - prev - (nums[i]*(nums.size()-i)) + (i*nums[i] - prev));\n            prev += nums[i];\n        }\n        return res;\n    }\n};\n```\n
['C++', 'JavaScript']