1752. Check if Array Is Sorted and Rotated
#array
Check if the array was originally sorted in non-decreasing order, then rotated some number of positions (including zero).
Intuition
If the array is sorted then it will have 0 inversion, if a sorted array is rotated either clockwise or anti-clockwise direction the amount of inversion will be 1.
In a sorted or rotated-sorted array, there can be at most one "drop" (i.e., an instance where an element is greater than its immediate successor). By checking for these drops, we can conclude whether the array satisfies the condition.
Complexity
Space Complexity
Time Complexity
Code
Last updated