1class Solution {2public:3int bestRotation(vector<int> &nums) {4int sz = nums.size();5vector<int> pointsForIShifts(2 * sz + 1, 0);6for (int i = 0; i < sz; i++) {7int l = 0, h = 0;8if (nums[i] <= i) {9l = 0;10h = i - nums[i];11pointsForIShifts[l] += 1;12pointsForIShifts[h + 1] -= 1;13}14l = i + 1;15h = i + sz - nums[i];16pointsForIShifts[l] += 1;17pointsForIShifts[h + 1] -= 1;18}19int maxP = pointsForIShifts[0], k = 0;20for (int i = 1; i < pointsForIShifts.size(); i++) {21pointsForIShifts[i] += pointsForIShifts[i - 1];22if (pointsForIShifts[i] > maxP) {23maxP = pointsForIShifts[i];24k = i;25}26}27return k;28}29};