Python O(N)
Calculating the diff once for 0th position, as the array is already sorted we know the next no. will either be same or greater by K.\n\nSo for the next no. the 
Calculating the diff once for 0th position, as the array is already sorted we know the next no. will either be same or greater by K.\n\nSo for the next no. the diff for each of the ith num will be smaller by K, which mean K*(n-i-1) i is 0-indexexd, likewise we need to add the same K times diff from the left of the array, which mean K*(i-1). This will give the sum of diff for the ith point.\n\nHope this is understandable. The overall time complexity is O(N).\n\n```\ndef getSumAbsoluteDifferences(nums):\n        last_diff, arr, i, cache = 0, [], 1, {}\n        n = len(nums)\n        while i < len(nums):\n            last_diff += abs(nums[i]-nums[0])\n            i += 1\n        \n        arr.append(last_diff)\n        i = 1\n        while i < len(nums):\n            if nums[i] in cache:\n                arr.append(cache[nums[i]])\n                i += 1\n                continue\n                \n            num_diff = nums[i] - nums[i-1]\n            last_diff = last_diff - num_diff * (n - i - 1)\n            if i-1 > 0:\n                last_diff += (i-1) * num_diff\n                \n            cache[nums[i]] = last_diff\n            arr.append(last_diff)\n            \n            i += 1\n            \n        return arr\n
[]