Golang simple observation
Observation\n\nWe know that the array is in a non-decreasing order.\nThat means that the number at index i will always be equal to or more than the number at in
**Observation**\n\nWe know that the array is in a non-decreasing order.\nThat means that the number at index i will always be equal to or more than the number at index i-1.\n\nWe also know that we can rewrite the nature of absolute difference into a simple substraction, ensuring that the bigger number is in front:\n```\nfunc absoluteDifference(a, b int) {\n\tif a > b {\n\t\treturn a - b\n\t}\n\treturn b - a\n}\n```\n\nWith these two key information we can split each absolute difference at index i into two parts: the summation of all number **before** index i and **after** index i. Here\'s an example:\n\n```\nInput: nums = [1,2,3,4,5]\nOutput: [10,7,6,7,10]\n\n// Here\'s a visualization on how to count result[2] = 6\nresult[2] = |1-3| + |2-3| + |3-3| + |4-3| + |5-3|\n\n// group into before and after\n= (|1-3| + |2-3|) + (|3-3| + |4-3| + |5-3|)\n\n// rewrite the absolute operations\n= (3-1 + 3-2) + (3-3 + 4-3 + 5-3)\n\n// group the same number i into one\n= (3+3 - 1-2) + (3+4+5 - 3-3-3)\n= (3*2 - 1-2) + (3+4+5 - 3*3)\n= (3*2 - (1+2)) + ((3+4+5) - 3*3)\n\n// and you can get the logic from generalization\nresult[i] = (nums[i]*i - sum[i]) + (sum[n]-sum[i] - nums[i]*(n-i))\n\n// where sum[i] means sum of values up to index i-1\n```\n\n\nFull code:\n```\nfunc getSumAbsoluteDifferences(nums []int) []int {\n    n := len(nums)\n    \n    total := 0\n    sum := make([]int, n)\n    \n    for i := 0; i < n; i++ {\n        total += nums[i]\n        sum[i] = total\n    }\n    \n    arr := make([]int, n)\n    for i := 0; i < n; i++ {       \n        before := (nums[i] * (i+1)) - (sum[i])\n        after := (total - sum[i]) - (nums[i] * (n-1-i))\n        arr[i] = before + after\n    }\n    \n    return arr\n}\n```
['Go']