Context: An array A[1..n] of distinct integers is called swap-sorted if there is some k, 1 ≤ k ≤ n, so that moving the last n − k elements of A (in the order in which they appear in A) before the first k elements of A results in a sorted array. (Note that a sorted array of distinct integers is swap-sorted: take k = n.) Also, the swap-sorted array must be in INCREASING ORDER.
Example: [ 4, 5, 6, 1, 2, 3] => move [1, 2, 3 ] to the front to [1, 2, 3, 4, 5, 6], which is considered swap-sorted. (increasing order)
Non-example: [ 3, 2, 1, 6 , 5, 4 ] => move [6, 5, 4 ] to the front to get [6, 5, 4, 3, 2, 1], not considered swap-sorted since decreasing order.
I need an algorithm Search(A, x) which, given a swap-sorted array of distinct integers A and an integer x, returns an index i, 1 ≤ i ≤ n, such that A[i] = x if such an index exists; and returns 0 if no such index exists.
The algorithm should run in O(log n) time, where n is the length of A.
Does anyone know how to approach this? Divide and conquer certainly seems like one way to do it, I just can't think of the steps.