🚀😎 Beats 100% | Easy To Understand 🔥🚀 | C++ | JAVA | PYTHON | JS
Intuition\nUPVOTE IF YOU FOUND THIS HELPFUL !!\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving t
# Intuition\nUPVOTE IF YOU FOUND THIS HELPFUL !!\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(1)\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        ios_base :: sync_with_stdio(false);\n        cin.tie(0);\n        cout.tie(0);\n        \n        int n = nums.size();\n        vector<int> ans(n);\n        int sum = accumulate(nums.begin(),nums.end(),0);\n        int Lnum = 0;\n        int Lsum = 0;\n        for(int i = 0; i < n; i++)\n        {\n            int Rsum = sum - Lsum - nums[i];\n            int Rnum = n - 1 - Lnum;\n            ans[i] = (Lnum * nums[i] - Lsum) + (Rsum - Rnum * nums[i]);\n            Lsum += nums[i];\n            Lnum++;\n        }\n        return ans;\n    }\n};\n```
['Array', 'Math', 'C', 'Prefix Sum', 'Python', 'C++', 'Java', 'JavaScript']