Python 3, one line, blazing fast
4 lines\n\nFirst calculate the sum... this is our current absolute difference as though we started with an element at the beginning of the array with value 0.\n
# 4 lines\n\nFirst calculate the sum... this is our current absolute difference as though we started with an element at the beginning of the array with value `0`.\n\nThen, for each adjascent pair, compute the difference...\n* Add that difference for each element on the left of the pair (use multiplication)\n* Subtract that difference for every element on the right of the pair (use multiplication)\n\nAnd apply that value on top of the absolute difference.\n\nTime: O(n)\nSpace: O(1) - the result is a generator instead of a list\n\n```python\nclass Solution:\n  def getSumAbsoluteDifferences(self, A: List[int]) -> List[int]:\n    val = sum(A)\n    for i, diff in enumerate(map(sub, A, chain([0], A))):\n      val += diff * (2*i - len(A))\n      yield val\n```\n\n# One line\n\nUse `accumulate` and `map` with functions from the `operators` library to calculate the absolute diffs.\nUse `count` to replace enumeration so we can multiply sooner.\nUse `islice` to throw away the first value.\n\nInterestingly, this ran in 800 ms, which is 50 ms faster than the start of the performance graph, way faster than 100% of submissions.\n\n```python\nclass Solution:\n  def getSumAbsoluteDifferences(self, A: List[int]) -> List[int]:\n    return islice(accumulate(map(mul, map(sub, A, chain([0], A)), count(-len(A), 2)), initial=sum(A)), 1, None)\n```
[]