Easy Java Solution 91% | Easy Approach |
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n- $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n- $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int minimumAverageDifference(int[] nums) {\n        int n = nums.length, pos = 0;\n        long min = Integer.MAX_VALUE;\n        long right = 0, left = 0, sum = 0;\n        for(int i = 0; i < n; i++){\n            sum += nums[i];\n        }\n        long val = 0;\n        for(int i = 0; i < n; i++){\n            left += nums[i];\n            right = sum - left;\n            if(i == n - 1)\n                val = Math.abs(left / n);\n            else if(i < n - 1)\n                val = Math.abs((left / (i + 1)) - (right / (n - i - 1)));\n            if(val < min){\n                min = val;\n                pos = i;\n            }\n        }\n        return pos;\n    }\n}\n```
['Java']