✅ very simple solution only 9 lines of code 🔥 Beats 99% 🚀
Intuition\n- I need to seperate the lower nembers and the higher numbers because the vector is sorted.\n\n# Approach\n- all i need the total sum that i stored i
# Intuition\n- I need to seperate the lower nembers and the higher numbers because the vector is sorted.\n\n# Approach\n- all i need the total sum that i stored in `sum` and the current sum that i stored in `cur`.\n\n- then i need to take all sum of all elements smaller than cur number the subtract `nums[i]*(i+1) - cur` why `i+1` because `i` zero based.\n\n- i need to take the sum of all elemnts i can do that with subtract `sum` with `cur` and do the same thing `(sum-cur)-nums[i]*(n-(i+1))`.\n\n- finally add them together.\n\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(n)$$\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> getSumAbsoluteDifferences(vector<int>& nums) {\n        ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);\n        vector<int>ans;\n        int sum=0,cur=0,n=nums.size(),i;\n        for(auto &it:nums)\n            sum+=it;\n        for(i=0;i<n;i++){\n            cur+=nums[i];\n            int low=((nums[i]*(i+1))-cur);\n            int high=(sum-cur)-(nums[i]*(n-(i+1)));\n            ans.push_back(low+high);\n        }\n        return ans;\n    }\n};\n```
['Array', 'Math', 'Prefix Sum', 'C++']