Prefix Sum | O(1) Space
C++:\n\nclass Solution {\npublic:\n    int minimumAverageDifference(vector<int>& nums) {\n        \n        int n(size(nums)), minAverageDifference(INT_MAX), in
# C++:\n```\nclass Solution {\npublic:\n    int minimumAverageDifference(vector<int>& nums) {\n        \n        int n(size(nums)), minAverageDifference(INT_MAX), index;\n        \n        long long sumFromFront(0), sumFromEnd(0);\n        for (auto& num : nums) sumFromEnd += num;\n        \n        for (int i=0; i<n; i++) {\n            sumFromFront += nums[i];\n            sumFromEnd -= nums[i];\n            int a = sumFromFront / (i+1); // average of the first i + 1 elements.\n            int b = (i == n-1) ? 0 : sumFromEnd / (n-i-1); // average of the last n - i - 1 elements.\n            \n            if (abs(a-b) < minAverageDifference) {\n                minAverageDifference = abs(a-b);\n                index = i;\n            }\n        }\n        return index;\n    }\n};\n```\n\n# Python:\n```\n\nclass Solution:\n    def minimumAverageDifference(self, nums: List[int]) -> int:\n\n        sumEnd, sumFront, res, diff, n = 0, 0, 0, 1e9, len(nums)\n        for num in nums:\n            sumEnd += num\n\n        for i in range(n):\n            sumFront += nums[i]\n            sumEnd -= nums[i]\n\n            avg1 = sumEnd//(n-1-i) if i != n-1 else 0\n            avg2 = sumFront//(i+1)\n\n            if abs(avg1-avg2) < diff:\n                diff = abs(avg1-avg2)\n                res = i\n        \n        return res\n```
['C++', 'Python3']