# Problem Statement Given an array `nums`, return `true` _if the array was originally sorted in non-decreasing order, then rotated **some** number of positions (including zero)_. Otherwise, return `false`. There may be **duplicates** in the original array. **Note:** An array `A` rotated by `x` positions results in an array `B` of the same length such that `A[i] == B[(i+x) % A.length]`, where `%` is the modulo operation. ## Constraints - `1 <= nums.length <= 100` - `1 <= nums[i] <= 100` # Solution If an array is in non-decreasing order, then for any two elements, the left will be less than or equal to the right. Because of this property, we can check adjacent numbers in an array, and if the left is ever greater than the right, we know it is not non-decreasing. For this problem in particular, there is a rotation, so the maximum value could be to the left of the minimum value. However, this unique case can only happen once (if our input is indeed a rotated non-decreasing array). Therefore, my solution checks adjacent elements, and return whether the ordering breaks lt; 2$ times. > [!WARNING] Watch out! > Make sure to append the first element to the end of `nums` so that you can check those "adjacent" elements ```python return sum(b < a for a,b in pairwise(nums + [nums[0]])) < 2 ``` Time Complexity: O($n$) | Space Complexity: O$(1)$