2855. Minimum Right Shifts to Sort the Array
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
class Solution:
    def minimumRightShifts(self, nums: list[int]) -> int:
        n = len(nums)
        
        # Check if the array is already sorted
        if nums == sorted(nums):
            return 0
        
        # Try to find the index where the array is rotated
        min_index = nums.index(min(nums))
        
        # Check if after rotation the array becomes sorted
        for i in range(n):
            if nums[(min_index + i) % n] != sorted(nums)[i]:
                return -1
        
        return (n - min_index) % n

```
['Python3']