A list of the sorted and rotated item is given. Items are sorted in ascending or descending order . For example, I have a list of sorted items as follows
10,12,14,16,18,20,51,53,54,59
Now this list is rotated X times, and then looks like this.
51,53,54,59,10,12,14,16,18,20
If you want to insert an item into this list, that would be the most efficient method for doing this.
The item to be inserted is 13. If the list moves linearly, false insertion may occur between 59 and 10.
I do not expect any code, rather a discussion of the algorithm is what I look forward to. The value 21 can be inserted as the first / last element. Consideration of boundary conditions, such as: - the inserted element, the first and last elements have the same value.