✅C++ | ✅Prefix & Suffix Sum | ✅Easy & Efficient
\n#CODE\n\n# Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(1)\nclass Solution {\npublic:\n    int minimumAverageDifference(vector<int>& nums) {\n
```\n#CODE\n\n# Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(1)\nclass Solution {\npublic:\n    int minimumAverageDifference(vector<int>& nums) {\n        long long int TotalSum=0,n=nums.size(),mini=INT_MAX,currSum=0,sumLeft=0,diff=0;\n        int idx=0;\n        for(int i=0;i<n;i++){\n            TotalSum+=nums[i];\n        }\n        if(n==1){\n            return 0;\n        }\n        for(int i=0;i<n;i++){\n            currSum+=nums[i];\n            sumLeft=TotalSum-currSum;\n            if(sumLeft==0){\n                 diff=floor(currSum/(i+1));\n            }else{\n                 diff=abs((currSum/(i+1))-(sumLeft/(n-i-1)));\n            }\n            if(mini>diff){\n                mini=diff;\n                idx=i;\n            }\n        }\n        return idx;\n    }\n};\n```\n\n![c668b758-003d-4e6f-a374-c128c2ef83e6_1655058432.5612516.jpeg](https://assets.leetcode.com/users/images/372db7f4-6604-4176-adea-a17e0620349b_1675493896.8659327.jpeg)\n
['C++']