Easy C++ | Prefix Array | O(N) time
\n\n\nclass Solution {\npublic:\n    int minimumAverageDifference(vector<int> &vec) {\n        long long n = vec.size();\n        vector<long long> pref(n, 0);\
\n\n```\nclass Solution {\npublic:\n    int minimumAverageDifference(vector<int> &vec) {\n        long long n = vec.size();\n        vector<long long> pref(n, 0);\n        pref[0] = vec[0];\n        for(long long i=1; i<n; i++) {\n            pref[i] = pref[i-1] + vec[i];\n        }\n        \n        int ans = -1;\n        long long minDiff = INT_MAX;\n        for(int i=0; i<n; i++) {\n            long long left = pref[i]/(i+1);\n            long long right = 0;\n            if(n-i-1 != 0) right = (pref[n-1] - pref[i])/(n-i-1);\n            long long diff = abs(left-right);\n            if(diff < minDiff) {\n                minDiff = diff;\n                ans = i;\n            }\n        }\n        return ans;\n    }\n};\n```
['C']