Prefix Sum
We handle the average of zero elements in the very end. \n\nC++\ncpp\nint minimumAverageDifference(vector<int>& nums) {\n    vector<long long> ps{0};\n    for (
We handle the average of zero elements in the very end. \n\n**C++**\n```cpp\nint minimumAverageDifference(vector<int>& nums) {\n    vector<long long> ps{0};\n    for (int n : nums)\n        ps.push_back(n + ps.back());\n    long long n = nums.size(), min_i = 0, sum = ps.back(), min_diff = INT_MAX;\n    for (int i = 1; i < n; ++i)\n        if (int diff = abs(ps[i] / i - (sum - ps[i]) / (n - i)); min_diff > diff) {\n            min_diff = diff;\n            min_i = i - 1;\n        }\n    return min_diff <= sum / n ? min_i : n - 1;\n}\n```
['C']