👍Runtime 905 ms  Beats 100.00% of users with Scala
Code\n\nobject Solution {\n    def bestRotation(nums: Array[Int]): Int = {\n        val size = nums.length\n        val rsc = new Array[Int](size)\n\n        fo
# Code\n```\nobject Solution {\n    def bestRotation(nums: Array[Int]): Int = {\n        val size = nums.length\n        val rsc = new Array[Int](size)\n\n        for (i <- 0 until size - 1) {\n            val value = nums(i)\n            val downPos = (i + 1 + size - value) % size\n            rsc(downPos) -= 1\n        }\n\n        val value = nums(size - 1)\n        if (value != 0) rsc(size - value) -= 1\n        var bestk = 0\n        var bestscore = rsc(0)\n        var score = rsc(0)\n\n        for (i <- 1 until size) {\n            score += rsc(i) + 1\n            if (score > bestscore) {\n                bestk = i\n                bestscore = score\n            }\n        }\n        bestk\n    }\n}\n```
['Scala']