My Solution
```
/**
 * Time Complexity: O(n)
 * Space Complexity: O(n)
 * where `n` is the length of the vector `nums`
 */
class Solution {
 public:
  int bestRotation(const vector<int> &nums) {
    const int n = static_cast<int>(nums.size());
    int sweep_line[n + 1];
    memset(sweep_line, 0, sizeof(sweep_line));
    for (int i = 0; i < n; ++i) {
      if (i < nums[i]) {
        // one step range exists,
        // which is from (`i` + 1) to (`i` + (`n` - `nums[i]`))
        ++sweep_line[i + 1];
        --sweep_line[i + (n - nums[i]) + 1];
      } else {
        // two step ranges exist
        // the step range 1 is from `0` to (`i` - `nums[i]`)
        ++sweep_line[0];
        --sweep_line[i - nums[i] + 1];
        
        // the step range 2 is from (`i` + 1) to (`n` - 1)
        if (i + 1 <= n - 1) {
          ++sweep_line[i + 1];
          --sweep_line[n];
        }
      }
    }
    
    int ret = -1;
    int score = 0;
    int max_score = 0;
    for (int step = 0; step < n; ++step) {
      score += sweep_line[step];
      if (score > max_score) {
        max_score = score;
        ret = step;
      }
    }
    return ret;
  }
};
```
['C++']