Java o(n) solution
```\nclass Solution {\n    \n    /\n    1.(nums[i]<=i)\n     gain from 0 till it is smaller ie (=diff), so subtract for diff+1 = i-nums[i]+1\n     also all the 
```\nclass Solution {\n    \n    /*\n    1.(nums[i]<=i)\n     gain from 0 till it is smaller ie (=diff), so subtract for diff+1 = i-nums[i]+1\n     also all the points after this idx till end will also gain, start is equal to i+1, to mobve it to end\n    \n    2.if(nums[i]>i)\n    we need to move this to end idx of array=i+1 rotation\n    till how many counts? see below\n    total possible rotation count=(end-start+1)=(end)-(nums[i])+1=n-1-nums[i]+1=n-nums[i];\n    startIdx=i+1\n    endIdx=n-nums[i]+i (=length+start-1)\n    so substract for n-nums[i]+i+1;\n    \n    */\n    public int bestRotation(int[] nums) {\n        \n        int n=nums.length;\n        int[] rotateIdxCount=new int[n+1];//indicates from which rotation count we will gain points till we subtract at another point\n        \n        for(int i=0;i<n;i++){\n            if(nums[i]<=i){\n                rotateIdxCount[0]++;\n                rotateIdxCount[i-nums[i]+1]--;\n                rotateIdxCount[i+1]++;\n            }else{\n                rotateIdxCount[i+1]++;\n                rotateIdxCount[i+n-nums[i]+1]--;\n            }\n        }\n        \n        int res=-1;\n        int max=0;\n        int curr=0;\n        \n        for(int i=0;i<n;i++){\n            curr+=rotateIdxCount[i];\n            if(curr>max){\n                res=i;\n                max=curr;\n            }\n        }\n        return res;\n    }\n}
[]