Problem statement

https://binarysearch.com/problems/Shift-to-Create-Range/

Solution

Find 1 first and then rotate array.

Complexity

It is O(n) for time and space.

Code

class Solution:
    def solve(self, nums):
        if nums.count(1) != 1: return False
        idx, n = nums.index(1), len(nums)
        nums = nums[idx:] + nums[:idx]
        return nums == list(range(1, n+1)) or nums == [1] + list(range(n, 1, -1))