✅ C++ using prefix sum, detailed explanation, one pass, O(nlongn)
\nclass Solution {\npublic:\n    int minimumAverageDifference(vector<int>& nums) {\n        vector<long> prefixSum(nums.size(), 0);\n        \n        long sum 
```\nclass Solution {\npublic:\n    int minimumAverageDifference(vector<int>& nums) {\n        vector<long> prefixSum(nums.size(), 0);\n        \n        long sum = 0;\n        \n        // store the accumulated sum at the index \n        for (int i = 0; i < nums.size(); i ++) {\n            sum += nums[i];\n            prefixSum[i] = sum;\n        }\n        \n          vector<pair<long,int>> vec; // set up a vec to store pairs with the first one as the res and the second one as the index\n        \n        for (int i = 0; i < nums.size(); i++) {\n            long firstPartSum = prefixSum[i];\n            long secondPartSum = prefixSum[nums.size()-1] - firstPartSum; \n            // the second part sum is just the last item from the vec subtract the firstPart sum\n            long firstPartSumAverage = firstPartSum/ (i+1);\n            long secondPartSumAverage = 0;\n            if (secondPartSum != 0) {\n                secondPartSumAverage = secondPartSum/(nums.size() - (i+1));\n            }\n            long res = abs(firstPartSumAverage - secondPartSumAverage);\n            vec.push_back({res, i});\n            // once we have the result store the result as a pair of {res, index} to vec\n        }\n        \n        sort(vec.begin(), vec.end()); // sort the vec from smallest to biggest\n        \n        return vec[0].second; // just return the first item\'s index from the vec\n    }\n};\n```
['C']