~12m
IntuitionApproachComplexity

Time complexity:
O(n), n - length of nums


Space complexity:
O(1)

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

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

# Complexity
- Time complexity:
O(n), n - length of nums

- Space complexity:
O(1)

# Code
```typescript []
function minimumRightShifts(nums: number[]): number {
    let savedIndex = 0

    let prev = nums[0]
    let isAlreadySorted = true
    for (let i = 1; i < nums.length; ++i) {
        if (nums[i] < prev) {
            savedIndex = i
            isAlreadySorted = false
            break
        }
        prev = nums[i]
    }

    if (isAlreadySorted) {
        return 0
    }

    nums = nums.slice(savedIndex).concat(nums.slice(0, savedIndex))
    // console.log(nums, 'xd hi')

    let unordered = false
    prev = nums[0]
    for (let i = 1; i < nums.length; ++i) {
        if (nums[i] < prev) {
            unordered = true
        }
        prev = nums[i]
    }

    return unordered ? -1 : nums.length - savedIndex
};
```
['TypeScript']