C++ O(n) Track Balance
cpp\nvector<int> getSumAbsoluteDifferences(vector<int>& n) {\n    int left = 0, right = accumulate(begin(n), end(n), 0), sz = n.size();\n    for (int i = 0; i <
```cpp\nvector<int> getSumAbsoluteDifferences(vector<int>& n) {\n    int left = 0, right = accumulate(begin(n), end(n), 0), sz = n.size();\n    for (int i = 0; i < sz; ++i) {\n        right -= n[i];\n        left += n[i];\n        n[i] = right - n[i] * (sz - i - 1) - left + n[i] * (i + 1);\n    }\n    return n;\n}\n```
[]