The "Check if Array Is Sorted and Rotated interview question" asks you to determine if a given array was originally sorted in non-decreasing order and then rotated some number of positions. For example, [3, 4, 5, 1, 2] is a sorted and rotated version of [1, 2, 3, 4, 5].
This "Check if Array Is Sorted and Rotated coding problem" is a popular question for companies like Google and Goldman Sachs. It tests a candidate's ability to identify a global property (sortedness) within a modified sequence. It evaluates "Array interview pattern" logic—specifically, how to count "descending steps" in a circular array.
The most efficient solution uses Linear Scan with Circular Continuity.
arr[i] <= arr[i+1] for all i. In a sorted and rotated array, there can be at most one "drop" where arr[i] > arr[i+1].arr[n-1] vs arr[0]).arr[i] > arr[(i+1)%n] is 1 or 0, then the array is a rotated sorted array.Array: [3, 4, 5, 1, 2]
[2, 1, 3, 4][1, 1, 1]). The condition is arr[i] > arr[i+1], not !=.Circular array problems are very common. Always think about using the modulo operator % or comparing the "tail" to the "head." This simple pass is much better than trying to find the pivot using binary search.