You are given a 0-indexed integer array nums of length n.

The average difference of the index i is the absolute difference between the average of the first i + 1 elements of nums and the average of the last n - i - 1 elements. Both averages should be rounded down to the nearest integer.

Return the index with the minimum average difference. If there are multiple such indices, return the smallest one.

Note:


	The absolute difference of two numbers is the absolute value of their difference.
	The average of n elements is the sum of the n elements divided (integer division) by n.
	The average of 0 elements is considered to be 0.


&nbsp;
Example 1:

Input: nums = [2,5,3,9,5,3]
Output: 3
Explanation:
- The average difference of index 0 is: |2 / 1 - (5 + 3 + 9 + 5 + 3) / 5| = |2 / 1 - 25 / 5| = |2 - 5| = 3.
- The average difference of index 1 is: |(2 + 5) / 2 - (3 + 9 + 5 + 3) / 4| = |7 / 2 - 20 / 4| = |3 - 5| = 2.
- The average difference of index 2 is: |(2 + 5 + 3) / 3 - (9 + 5 + 3) / 3| = |10 / 3 - 17 / 3| = |3 - 5| = 2.
- The average difference of index 3 is: |(2 + 5 + 3 + 9) / 4 - (5 + 3) / 2| = |19 / 4 - 8 / 2| = |4 - 4| = 0.
- The average difference of index 4 is: |(2 + 5 + 3 + 9 + 5) / 5 - 3 / 1| = |24 / 5 - 3 / 1| = |4 - 3| = 1.
- The average difference of index 5 is: |(2 + 5 + 3 + 9 + 5 + 3) / 6 - 0| = |27 / 6 - 0| = |4 - 0| = 4.
The average difference of index 3 is the minimum average difference so return 3.


Example 2:

Input: nums = [0]
Output: 0
Explanation:
The only index is 0 so return 0.
The average difference of index 0 is: |0 / 1 - 0| = |0 - 0| = 0.


&nbsp;
Constraints:


	1 &lt;= nums.length &lt;= 105
	0 &lt;= nums[i] &lt;= 105


from itertools import accumulate

class Solution:
    def minimumAverageDifference(self, nums: List[int]) -> int:
        size = len(nums)

        nums[::] = list(accumulate(nums))
        total = nums[-1]
        
        min_tuple = [0, sys.maxsize]
        
        for (i, n) in enumerate(nums):
            i = i + 1
            avg_i = floor(n/i)
            
            diff = size - i
            total_avg = floor((total - n) / (diff if diff>0 else 1))

            avg = abs( avg_i - total_avg) 
            if min_tuple[1] > avg:
                min_tuple[1] = avg
                min_tuple[0] = i - 1
            
        return min_tuple[0]
class Solution {
    public int minimumAverageDifference(int[] nums) {
        if(nums.length == 1){
            return 0;
        }
        int idx = -1;
        long min = Integer.MAX_VALUE;
        long suml = nums[0];
        long sumr = 0;
        for(int i = 1; i < nums.length; i++){
            sumr += nums[i];
        }
        int i = 1;
        int calc = 0;
        int left = 1;
        int right = nums.length - left;
        long[] arr = new long[nums.length];
        while(i < nums.length){
            long diff = Math.abs((suml/left) - (sumr/right));
            arr[calc] = diff;
            if(diff < min){
                min = diff;
                idx = calc;
            }
            suml += nums[i];
            sumr -= nums[i];
            left++;
            right--;
            calc++;
            i++;
        }
        arr[calc] = suml/nums.length;
        if(arr[calc] < min){
            min = arr[calc];
            idx = nums.length - 1;
        }
        // for(i = 0; i < nums.length; i++){
        // System.out.println(arr[i]);
        // }
        return (int)idx;
    }
}
class Solution {
public:
    int minimumAverageDifference(vector<int>& nums) {

        int n(size(nums)), minAverageDifference(INT_MAX), index;

        long long sumFromFront(0), sumFromEnd(0);
        for (auto& num : nums) sumFromEnd += num;

        for (int i=0; i<n; i++) {
            sumFromFront += nums[i];
            sumFromEnd -= nums[i];
            int a = sumFromFront / (i+1); // average of the first i + 1 elements.
            int b = (i == n-1) ? 0 : sumFromEnd / (n-i-1); // average of the last n - i - 1 elements.

            if (abs(a-b) < minAverageDifference) {
                minAverageDifference = abs(a-b);
                index = i;
            }
        }
        return index;
    }
};
```/**
 * @param {number[]} nums
 * @return {number}
 */
 var minimumAverageDifference = function(nums) {
    if (nums.length == 1) return 0;
    let mins = 100000, resultIndex, leftTotal = 0;
    let rightTotal = nums.reduce((a,b)=>a + b);
    let numLength = nums.length;
    nums.forEach((data, index)=> {
        leftTotal += data;
        rightTotal -= data;
        let currentAverageDiff = Math.abs(Math.floor(leftTotal/(index+1)) - Math.floor(rightTotal/(numLength-index-1) || 0));
        if (currentAverageDiff < mins) {
            resultIndex = index;
            mins = currentAverageDiff;
        }
    });
    return resultIndex;
};
Minimum Average Difference