It works, but looks clumsy
Three ideas that I tried to implement here:\n1. Avoid casting\n2. Avoid inside-loop guard clauses, i.e. checks for edge cases like division by zero\n3. Return e
Three ideas that I tried to implement here:\n1. Avoid casting\n2. Avoid inside-loop guard clauses, i.e. checks for edge cases like division by zero\n3. Return early if the array is all zeroes\n\nTo 1: The only casting is done when summing up the array. Seems unavoidable.\nTo 2: Check the last index when returning (not inside the for loop).\n```csharp\npublic class Solution\n{\n    public int MinimumAverageDifference(int[] nums)\n    {\n        long sum = nums.Sum(n => (long)n);\n        if (sum == 0) return 0;\n\n        int minIndex = 0;\n        int len = nums.Length;\n        long front = 0;\n        long minDiff = long.MaxValue;\n\n        for (int i = 1; i < len; i++)\n        {\n            front += nums[i - 1];\n            long diff = Math.Abs((sum - front) / (len - i) - front / i);\n            if (diff < minDiff) (minDiff, minIndex) = (diff, i - 1);\n        }\n\n        return sum / len < minDiff ? len - 1 : minIndex;\n    }\n}\n```
['C#']