Simple O(n) time O(1) Space beginner friendly.
Intuition\nwe have to take count of left and right sum at each index.\n\n# Approach\nwe will be taking left sum and right sum.\nwe will find the average at each
# Intuition\nwe have to take count of left and right sum at each index.\n\n# Approach\nwe will be taking left sum and right sum.\nwe will find the average at each index.\nIf the current difference is less than last minimum difference than update last minimum difference and ans index.\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\n    public int minimumAverageDifference(int[] nums) {\n        int n=nums.length;\n        //if length==1 difference=0\n        if(n==1)return 0;\n        // initialsing left and right sum\n        long right=0,left=0;\n        //ans will contain index\n        int ans=0;\n        //mina will contain minimum difference found till now\n        long mina=100001;\n        for(Integer i:nums){right+=i;}//right=total sum\n\n        //iterating on array and obtaining corresponding difference\n        for(int i=0; i<n; i++){\n\n            //left sum increases on each iteration\n            left+=nums[i];\n            //right sum decreases on each iteration\n            right-=nums[i];\n            //avl -> average of left side\n            long avl=left/(i+1);\n            //avr-> average of right side\n            long avr=0;\n            //for last index right=0 , avr=0\n            if(i!=n-1){avr=right/(n-1-i);}\n\n            //if current difference is less than mina \n            if(Math.abs(avl-avr)<mina)\n            {\n                //update mina \n            mina=Math.abs(avl-avr);\n            //update ans index\n            ans=i;}\n        }\n        // return ans index\n        return ans;\n    }\n}\n//Thank you\n//Upvote if found helpful.\n```
['Java']