Java  O(n)Time O(n) Space Solution
Let\'s go through an example first. If the input is{2,4,1,3,0}, We write down all status when rotate k steps.\nNumber:::::: 2 4 1 3 0\n k = 0    index: 0 1 2 3 
Let\'s go through an example first. If the input is{2,4,1,3,0}, We write down all status when rotate k steps.\nNumber:::::: 2 4 1 3 0\n k = 0    index: 0 1 2 3 4\n k = 1    index: 4 0 1 2 3\n k = 2    index: 3 4 0 1 2\n k = 3    index: 2 3 4 0 1\n k = 4    index: 1 2 3 4 0\n \n If we look in each column, then index for one particular number is somehow decrease with a valley(0). We want to know in which K steps the index is greate or equal than the corresponding number. For number 2, k should be{1,2,3}, for number 1, k should be{0,1,3,4}.\n So our task is to collect all k rows in which the index >= number for each paritular number.\n 1. If number > index in original array: \n\t   As index is decreasing, so we need to find in which row the index is equals to (length - 1), the largest index of array. Then go down until index == number. \n\t\t \n2. If number <= index in original array:\n\t  k = 0 is always valid, and 0 through the row in which index == number is the last valid row. Also, don\'t forget the index == len - 1 this corner case;\n\nThere are some math tricks from maybe high school: largest index row = (index + 1) % len; Row in which index == number = (index + len - num) % len;\nWe just need to update count[min] and count[max] to avoid O(n) time to record our result.\n\n\n```\nclass Solution {\n    public int bestRotation(int[] A) {\n        int[] count = new int[A.length + 1];\n        int len = A.length;\n        for(int index = 0; index < A.length; index ++){\n            int num = A[index];\n            if(index < num){\n                int maxLenK = (index + 1) % len;\n                int ori = (index + len - num) % len;\n                count[maxLenK] ++;\n                count[ori + 1] --;\n            }else{      // index >= num\n                int ori = (index + len - num) % len;\n                count[0] ++;\n                count[ori + 1] --;\n                if(index != len - 1){\n                    count[(index + 1) % len] ++;\n                    count[len] --;\n                }\n            }\n        }\n        int max = count[0];\n        int res = 0;\n        for(int i = 1; i < len; i ++){\n            count[i] = count[i] + count[i - 1];\n            if(count[i] > max){\n                max = count[i];\n                res = i;\n            }            \n        }\n        return res;\n    }\n}\n```
[]