798. Smallest Rotation with Highest Score
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public:\n  int bestRotation(vector<int>& nums) {\n    const int n = nums.size();\n    // rotate[i] := how many points losing after rotating left i times\n    vector<int> rotate(n);\n\n    // Rotating i - nums[i] times makes nums[i] == its new index.\n    // So, rotating i - nums[i] + 1 times will "start" to make nums[i] > its\n    // index, Which is the starting index to lose point\n    for (int i = 0; i < n; ++i)\n      --rotate[(i - nums[i] + 1 + n) % n];\n\n    // Each time we rotate, we make index 0 to index n - 1, so we get 1 point.\n    for (int i = 1; i < n; ++i)\n      rotate[i] += rotate[i - 1] + 1;\n\n    return distance(begin(rotate), max_element(begin(rotate), end(rotate)));\n  }\n};\n\n```
['C++']