Simple Java Solution with Time Complexity:O(N) && Space:O(1)
Hello Guys.....\n\tThis particular problem can be solved using O(N) complexity. To be more accurate, we need run time of O(2N) where N is the length of the arra
***Hello Guys.....***\n\tThis particular problem can be solved using O(N) complexity. To be more accurate, we need run time of O(2N) where N is the length of the array. Firstly, we need to calculate the ***total sum*** of the array. We need a long variable since the sum could be large.\n\t\tSecondly we iterrate over the array once again and add each number to the **leftSum**. We find the **rightSum** using the **leftSum** and **totalSum**. Here is the java solution for the problem using the above approach.\n```\nclass Solution {\n    public int minimumAverageDifference(int[] nums) {\n        long sum=0,leftSum=0;\n        int leftCount=1,rightCount=nums.length - 1;\n        for (int i=0;i<nums.length;i++)\n            sum+=nums[i];\n        long lhs,rhs,min=999999999999999l;\n        int index=0;\n        for (int i=0;i<nums.length;i++)\n        {\n            leftSum+=nums[i];\n            lhs=leftSum/leftCount;\n            rhs=(rightCount>0)?(sum-leftSum)/rightCount:0;\n            long avgDiff=((lhs-rhs)>0?lhs-rhs:rhs-lhs);\n            if (i==0){min=avgDiff;}\n            if (avgDiff<min)\n            {\n                min=avgDiff;\n                index=i;\n            }\n            leftCount++;\n            rightCount--;\n         }\n         return index;       \n    }\n}\n```\n\n\tWe can use the same approach, for solving similar problems such as [2270. Number of Ways to Split Array](http://leetcode.com/problems/number-of-ways-to-split-array/)\n\t\n***Happy Coding \nHave a nice day  :)***\n\n
['Array', 'Prefix Sum']