O(1) Space | O(N) Time | Java
Intuition\n Describe your first thoughts on how to solve this problem. \nWe calculate the sum of all elements beforehand, which is of O(N) complexity\nWe store 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe calculate the sum of all elements beforehand, which is of O(N) complexity\nWe store the prefix sum in a variable as we traverse through the array, this is the sum of the left part of the partition. \nTo calculate the right sum, there are two conditions\n1. if the no. of elements is zero, then we simply subtract 0 from the left average\n2. if the no. of elements is greater than zero, then we find the right sum by subtracting current left sum from the total sum\n\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n# Note\nHere, we use \'long\' datatype instead of int for all the variables storing elements as \'int\' range is not enough for all the testcases, for indices we use \'int\'. \n\n# Code\n```\nclass Solution {\n    public int minimumAverageDifference(int[] nums) {\n        int n = nums.length;\n        if (n == 1) return 0;\n\n        long tot = 0;\n        for(int i : nums) \n            tot += i;\n\n        long left = 0;\n        long minDiff = Integer.MAX_VALUE;\n        int ans = -1;\n        for (int i = 0; i < n; ++i) {\n            left += nums[i];\n            long right = tot - left;  \n            long diff = Math.abs((left / (i + 1)) - \n                ((n - i == 1) ? 0: right / (n - i - 1)));\n                    \n            if (diff < minDiff) {\n                minDiff = diff;\n                ans = i;\n            }\n        }\n        return ans;\n    }\n}\n```
['Prefix Sum', 'Java']