Java, Prefix and suffix ,O(n)
\nclass Solution {\n    public int[] getSumAbsoluteDifferences(int[] nums) {\n        int suf=0;\n        int pref=0;\n        int[] result=new int[nums.length]
```\nclass Solution {\n    public int[] getSumAbsoluteDifferences(int[] nums) {\n        int suf=0;\n        int pref=0;\n        int[] result=new int[nums.length];\n        \n        for(int i=0;i<nums.length;i++) suf+=nums[i];\n        for(int i=0;i<nums.length;i++){\n            if(i>0)result[i]=Math.abs(pref-(nums[i]*i));\n            pref+=nums[i];\n            result[i]+=Math.abs((suf-pref)-(nums[i]*(nums.length-i-1)));\n        }\n        return result;\n    }\n}\n```
['Prefix Sum', 'Java']