Java sol
\nclass Solution {\n    public int bestRotation(int[] A) {\n        int res=-1;\n        int point=0;int max=-1;\n        int start[]=new int[A.length];\n      
```\nclass Solution {\n    public int bestRotation(int[] A) {\n        int res=-1;\n        int point=0;int max=-1;\n        int start[]=new int[A.length];\n        int end[]=new int[A.length];\n        for(int i=0;i<A.length;i++) {\n            if(A[i]<=i)start[0]++;\n            int dif=i-A[i]+1;\n            if(dif<0)dif+=A.length;\n            end[dif%A.length]++;\n            start[(i+1)%A.length]++;\n        }\n        for(int k=0;k<A.length;k++){\n            point+=start[k];\n            point-=end[k];\n            if(point>max){\n                max=point;\n                res=k;\n            }\n        }\n        return res;\n    }\n}\n```
[]