Short and easy to understand (Must watch solution !!)
Explanation\n1. Total Sum Calculation:\n\n    - First, calculate the total sum of all elements in nums (totalSum). This represents the sum of all elements in th
# Explanation\n1. Total Sum Calculation:\n\n    - First, calculate the total sum of all elements in nums (totalSum). This represents the sum of all elements in the array.\n2. Prefix Sum and Result Calculation:\n\n    1. Prefix Sum (prefixSum): This keeps track of the sum of all elements before the current element nums[i].\n    1. For each element nums[i], compute the sum of absolute differences:\n        - Left Contribution: nums[i] * i - prefixSum\n            - This represents the total difference contributed by all elements to the left of nums[i].\n        - Right Contribution: (totalSum - prefixSum - nums[i]) - nums[i] * (n - i - 1)\n            - This represents the total difference contributed by all elements to the right of nums[i].\n    1. The result for each element is the sum of the left and right contributions.\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```java []\nclass Solution {\n    public int[] getSumAbsoluteDifferences(int[] nums) {\n        int n = nums.length;\n        int res[] = new int[n];\n        int totalSum = 0;\n        int prefixSum = 0;\n        for(int i = 0; i < nums.length; i++){\n            totalSum += nums[i];\n        }\n        for(int i = 0;i<nums.length; i++){\n            res[i] = (nums[i] * i - prefixSum) + ((totalSum - prefixSum - nums[i]) - nums[i] * (n - i - 1));\n            prefixSum += nums[i];\n        }\n\n        return res;\n    }\n}\n```\n\n# Please UpVote if it helped you by any means!! \n# Thank You!!
['Prefix Sum', 'Java']