2025-08-15 11:31:10 +0000 UTC

Check if Array Is Sorted and Rotated

Code

class Solution:
    def check(self, nums: List[int]) -> bool:
        prev = nums[0]
        new_start = 0
        for num in nums[1:]:
            if num >= prev:
                pass
            elif new_start == 0:
                new_start = num
            else:
                return False
            prev = num
        if new_start == 0:
            return True
        return nums[0] >= nums[-1]