✅ C++ Simple | Prefix Sum | O(n)
\nclass Solution {\npublic:\n    \n    int minimumAverageDifference(vector<int>& nums) \n    {    \n        int ans_idx=0;\n        int n=nums.size();\n        
```\nclass Solution {\npublic:\n    \n    int minimumAverageDifference(vector<int>& nums) \n    {    \n        int ans_idx=0;\n        int n=nums.size();\n        if(n==1) return 0;\n        \n        long long ans = INT_MAX, sum = 0;\n        \n        for(int i=0;i<n;i++)\n            sum += nums[i];\n        // prefix sum\n        vector<long long>pre(n);\n        \n        pre[0] = nums[0];\n        for(int i=1;i<n;i++)\n            pre[i] = nums[i] + pre[i-1];\n        \n        for(int i=0;i<nums.size();i++)\n        {    \n            long long firstSum = pre[i];\n            long long lastSum = (sum - pre[i]);\n            long long diff=0;\n            \n            if((n-i-1)!= 0)\n                diff = abs(firstSum/(i+1) - lastSum/(n-i-1));\n            else\n                diff = firstSum/(i+1) - 0;\n            \n            if(diff < ans)\n            {\n                ans = diff;\n                ans_idx = i;\n            }\n        }\n        return ans_idx;\n    }\n};\n```\n***Thanks for Upvoting !***\n\uD83D\uDE42
['Array', 'C', 'Prefix Sum', 'C++']