Java Simple Solution O(n) time complexity and O(1) space complexity
\n# Code\n\nclass Solution {\n    public int minimumAverageDifference(int[] nums) {\n       int n=nums.length;\n       long tsum=0;\n       for(int i=0;i<n;i++)
\n# Code\n```\nclass Solution {\n    public int minimumAverageDifference(int[] nums) {\n       int n=nums.length;\n       long tsum=0;\n       for(int i=0;i<n;i++)\n            tsum+=nums[i];\n        int ans=-1;  //index of minimum average difference\n        int mindif=Integer.MAX_VALUE; //value of minimum average difference\n        long lsum=0;\n        long rsum=0;\n        for(int i=0;i<n;i++)\n        {\n            //count the no of elements of left and right respectively\n            int lcount=i+1;\n            int rcount=n-lcount;\n            // left sum and right sum\n            lsum+=nums[i];\n            rsum=tsum-lsum;\n            // Average of left and right\n            long lavg=(lsum/lcount);\n            long ravg=(rcount==0)?0:rsum/rcount;\n            //Absolute difference\n            int absdiff=(int)Math.abs(lavg-ravg);\n\n            if(mindif>absdiff)\n            {\n                mindif=absdiff;\n                ans=i;\n            }\n\n\n\n            \n            \n        }\n\n        return ans;\n       \n    }\n}\n```
['Java']