Easy To Understand || Simple Logic || O(N) Solution || C++ || IIT Roorkee
Complexity\n- Time complexity:O(N)\n- Space complexity:O(N)\n\n# Code\n\nclass Solution {\npublic:\n    int bestRotation(vector<int>& nums) \n    {\n     int to
# Complexity\n- Time complexity:O(N)\n- Space complexity:O(N)\n\n# Code\n```\nclass Solution {\npublic:\n    int bestRotation(vector<int>& nums) \n    {\n     int tot=0;\n     int n=nums.size();\n     unordered_map<int,int>mp;\n     for(int i=0;i<nums.size();i++)\n     {\n         if(nums[i]<=i)\n         {\n              int k=((i+1)-nums[i]);\n              tot++;\n              mp[k]++;\n         }\n     }\n     int count=1;\n     int maxi=tot;\n     int ans=0;\n     for(int j=0;j<nums.size();j++)\n     {    \n          tot=tot-mp[count];\n          if(n>nums[j])\n          {\n              int k=((n-nums[j])+count);\n              tot++;\n              mp[k]++;\n          }\n          count++;\n          if(maxi<tot)\n          {\n              maxi=tot;\n              ans=j+1;\n          }\n     }\n     return ans;    \n    }\n};\n```
['Array', 'Ordered Map', 'Counting', 'Counting Sort', 'C++']