Easy  CPP Solution Using Prefix Array | | Easy to Understand
Intuition\n Describe your first thoughts on how to solve this problem. \n- We have to find the element whose average difference is lowest and if there are multi
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- We have to find the element whose average difference is lowest and if there are multiple such elements then we have to return index of first such occuring element.\n- So, we can use Prefix Array for calculating average difference of all elements and then return the index of least average difference element.\n- We need to create the Prefix Array of long long int to avoid integer overflows.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. First we create a Prefix Array and then at every index we store the sum of elements till that index.\n2. Next at every index we store average difference (absolute difference of average of right elements and left elements) for the element at that index.\n3. As the last element has no right side element, it will store the average of all elements.\n4. Lastly we find the minimum element from the array of average difference .\n5. After iterating in array we find the minimum element and return its index.\n Hope You Understand!\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$ For Prefix Array\n\n# Code\n```\nclass Solution {\npublic:\n    int minimumAverageDifference(vector<int>& nums) {\n\n        // Using Prefix Array\n\n        vector<long long int>arr(nums.size(),0);\n        arr[0]=nums[0];\n        for(int i=1;i<nums.size();i++)\n        {\n            arr[i] += arr[i-1] + nums[i]; // Created a prefix array\n        }\n        for(int i=0;i<nums.size()-1;i++)\n        {\n            arr[i] = arr[i]/(i+1) - ((arr[nums.size()-1] - arr[i])/(nums.size()-i-1)); // To store the difference of average at that index\n\n            arr[i] = abs(arr[i]);\n        }\n\n        arr[nums.size()-1] /= nums.size(); //Last index will have no elements on right side so it will store average of all.\n\n        long long int &temp = *min_element(arr.begin(),arr.end());// to find the smallest element in array with least average difference.\n\n        for(int i=0;i<nums.size();i++)\n        {\n            if(arr[i]==temp)return i;//returning index of smallest element.\n        }\n        return 0;\n    }\n};\n```
['Array', 'Prefix Sum', 'C++']