How to find an index of an number in a sorted array with an offset
Consider that I have an array of sorted numbers with 0 to N-1 offset where
N is the lenght of the array. A completely sorted array has 0 zero offset
as given below
[1, 2, 3, 4, 5, 6]
An array [3, 4, 5, 6, 1, 2] has an offset of 4 as the number starting from
4th number and wrapping around to the first.
The assignment question is how to find an index of a number in array. For
a sorted array, the solution would obviously be a binary search to find
the index (with or without recursion).
How do you find the index of a number in an array with an offset. The
offset is not known. I would like an outline for the solution and I will
try to implement it in a language I am comfortable in.
No comments:
Post a Comment