Simple solution with a flag | simpler than top voted ones | T: O(n) M: O(1)
Intuition & ApproachCompare elements from index 1 to n (0th) with a previous element.If flagged more than once, return -1. Else return n-i.Complexity
Time compl
# Intuition & Approach

Compare elements from index `1` to `n` (0th) with a previous element.

If flagged more than once, return `-1`. Else return `n-i`.

# Complexity

- Time complexity: $$O(n)$$
- Space complexity: $$O(1)$$

# Code
```cpp []
class Solution {
public:
    int minimumRightShifts(vector<int>& nums) {
        int f = 0, n = nums.size();
        for (int i = 1; i <= n; i++)
            if (nums[i - 1] > nums[i % n]) {
                if (f)
                    return -1;
                f = n - i;
            }
        return f;
    }
};
```
['C++']