C++ O(n) time and O(1) Space with Prefix Sum
\nApproach :\n\n Find sum as sum of all n elements and keep a prefSum for storing sum till i index.\n Use prefSum for finding sum ofi+1 elements which is prefSu
\n`Approach : `\n\n* Find sum as `sum` of all n elements and keep a prefSum for storing sum till i index.\n* Use `prefSum ` for finding sum of` i+1` elements which is prefSum it self and `sum-prefSum` for finding sum of remaining `n-i` elements.\n* Check for edge case when `i = n-1` and find minimum average difference.\n* Now iterate again to find minimum index with the minimum average difference.\n\n**Time :  O(n)\nSpace :  O(1)**\n\n\n```\nclass Solution {\npublic:\n    int minimumAverageDifference(vector<int>& v){\n        long long sum = 0, prefSum = 0;\n        int n = v.size();\n        long long mn = 1e9;\n        for(auto &ele:v) sum += ele;\n        for(int i=0;i<n;i++){\n            prefSum += v[i];\n            if(i!=n-1)\n            mn = min(mn,abs(prefSum/(i+1) - (sum-prefSum)/(n-i-1)));\n            else mn = min(mn,prefSum/(i+1));\n        }\n        prefSum = 0;\n        for(int i=0;i<n;i++){\n            prefSum += v[i];\n            long long val = 0;\n            if(i!=n-1)\n            val = abs(prefSum/(i+1) - (sum - prefSum)/(n-i-1));\n            else val = prefSum/(i+1);\n            if(val==mn) return i;\n        }\n        return -1;\n    }\n};\n```
['Array', 'C', 'Prefix Sum', 'C++']