Java O(n)O(n)
\nclass Solution {\n    public int bestRotation(int[] A) {\n        int[] temp = new int[A.length];\n        for(int i = 0; i< A.length; i++){\n            if(A
```\nclass Solution {\n    public int bestRotation(int[] A) {\n        int[] temp = new int[A.length];\n        for(int i = 0; i< A.length; i++){\n            if(A[i] <= A.length) \n                temp[(i - A[i]) >= 0? i - A[i]: i + A.length - A[i]] += 1;\n        }\n        int min = 0, ret = 0;\n        for(int i = 0; i < A.length; i++){\n            if (A[i] > i)min++;\n        }\n        int count = min;\n        for(int i = 0; i < A.length - 1; i++){\n            if(A[i] <= A.length)count--;\n            count += temp[i];\n            if(count < min)\n                {min = count;\n                ret = i + 1;}\n        }\n        return ret;\n    }\n}\n```
[]