My First Leet Code Solution
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```\n#include <vector>\n#include <iostream>\nusing namespace std;\n\nclass Solution {\npublic:\n    int bestRotation(vector<int>& nums) {\n        int n = nums.size();\n        vector<int> change(n, 0);\n\n        // Calculate initial score for k = 0\n        int initial_score = 0;\n        for (int i = 0; i < n; ++i) {\n            if (nums[i] <= i) {\n                ++initial_score;\n            }\n            \n            int lower_bound = (i + 1) % n;\n            int upper_bound = (i - nums[i] + n + 1) % n;\n            \n            change[lower_bound] += 1;\n            if (upper_bound < n) {\n                change[upper_bound] -= 1;\n            }\n            if (lower_bound > upper_bound) {\n                change[0] += 1;\n            }\n        }\n\n        // Calculate scores for each k using the change array\n        int max_score = initial_score;\n        int max_k = 0;\n        int current_score = initial_score;\n        \n        for (int k = 1; k < n; ++k) {\n            current_score += change[k];\n            if (current_score > max_score) {\n                max_score = current_score;\n                max_k = k;\n            }\n        }\n\n        return max_k;\n    }\n};\n\n```
['C++']