Java | Prefix sum
The only catch here is to test the case taking all in the first average separetely else division by 0 exception will be encountered\n\nclass Solution\n{\n    pu
The only catch here is to test the case taking all in the first average separetely else division by 0 exception will be encountered\n```\nclass Solution\n{\n    public int minimumAverageDifference(int[] nums)\n    {\n        int N = nums.length, id = 0;\n        long min = Integer.MAX_VALUE;\n        long[] pre = new long[N];\n        pre[0] = nums[0];\n        for(int i = 1; i < N; i++)\n            pre[i] = pre[i-1]+nums[i];\n        for(int i = 0; i < N-1; i++)\n        {\n            long diff = (long)(Math.abs(Math.round(pre[i]/(i+1) - Math.round((pre[N-1]-pre[i])/(N-i-1)))));\n            if(diff < min)\n            {\n                id = i;\n                min = diff;\n            }\n        }\n        if(min > pre[N-1]/N) // Taking all on the first/left\n            return N-1;\n        return id;\n    }\n}\n```
['Java']