scala
scala\ndef minimumAverageDifference(nums: Array[Int]): Int = {\n  val list = nums.map(_.toLong).toList\n  goMinAv(list, 0, 0, list.sum, nums.length, Int.MaxValu
```scala\ndef minimumAverageDifference(nums: Array[Int]): Int = {\n  val list = nums.map(_.toLong).toList\n  goMinAv(list, 0, 0, list.sum, nums.length, Int.MaxValue, 0)\n}\n\ndef goMinAv(nums: List[Long], leftSum: Long, ind: Int, rightSum: Long, rightCount: Int, minimum: Long, minimumInd: Int): Int =\n  nums match {\n    case Nil => minimumInd\n    case h :: tail =>\n      val lSum = leftSum + h\n      val rSum = rightSum - h\n      val lCount = ind + 1\n      val rCount = rightCount - 1\n\n      val rAvg = if(rCount == 0) 0 else rSum / rCount\n      val avDiff = math.abs(lSum / lCount - rAvg)\n      val (min, minInd) = if(avDiff < minimum) (avDiff, ind) else (minimum, minimumInd)\n\n      goMinAv(tail, lSum, lCount, rSum, rCount, min, minInd)\n  }\n  ```
['Scala']