✅ C++ || EASY || DETAILED EXPLAINATION || O(N)
PLEASE UPVOTE IF YOU FIND MY APPROACH HELPFUL, MEANS A LOT \uD83D\uDE0A\n\nIntuition: We just have to take average difference and return the index giving minimu
**PLEASE UPVOTE IF YOU FIND MY APPROACH HELPFUL, MEANS A LOT \uD83D\uDE0A**\n\n**Intuition:** We just have to take average difference and return the index giving minimum average difference.\n\n**Approach:**\n* Take out `totalsum` which will be sum of all n elements and `currentsum` which will be the sum till `ith` index.\n* Calculate the `avg1` till ith index and `avg2` till n-1-ith index.\n* Now take absolute diff btw `avg1` and `avg2` and keep tracking the index giving minimum diff.\n* return the index giving minimum diff.\n\n```\nclass Solution {\npublic:\n    int minimumAverageDifference(vector<int>& nums) {\n        long totalsum = 0, currentsum = 0;\n        int n = nums.size();\n        \n        // calc totalsum\n        for(auto i : nums)\n            totalsum += i;\n        \n        int mini = INT_MAX;\n        int indexans = 0;\n        \n        // calc the avg1 till ith index and avg2 till n-1-ith index\n        // now take absolute diff btw avg1 and avg2 and keep tracking the index giving minimum diff\n        // return the index giving minimum diff\n        for(int i=0; i<n; i++)\n        {\n            currentsum += nums[i];\n            int avg1 = currentsum/(i+1);\n            if(i==n-1)\n            {\n                if(avg1<mini)\n                    return n-1;\n                else\n                    break;\n            }\n            int avg2 = (totalsum - currentsum)/(n-i-1);\n            \n            if(abs(avg1-avg2)<mini)\n            {\n                mini = abs(avg1-avg2);\n                indexans = i;\n            }\n        }\n        \n        return indexans;\n    }\n};\n```\n**Time Complexity** => `O(N)`\n**Space Complexity** => `O(1)`\n\n![image](https://assets.leetcode.com/users/images/f676b124-08ca-4c1c-adc9-0cc3bf101cee_1670122663.4309115.png)\n
['C++']