https://online.codingblocks.com/app/player/199544/content/197161/4945/code-challenge
How to do this using binary search
https://online.codingblocks.com/app/player/199544/content/197161/4945/code-challenge
How to do this using binary search
Talking straightly, the Question is to find an element in the Sorted but Rotated array. One can imagine this Question by finding the pivot element and then rotate it to get the original array and can use Binary search to find the element but the main point to consider is that:-
Here is the Algorithm that will let you find the element in O(log n)
a) If the key to be searched lies in the range from arr[l] to
arr[mid], recur for arr[l..mid].
b) Else recur for arr[mid+1..r]
a) If the key to be searched lies in the range from arr[mid+1]
to arr[r], recur for arr[mid+1..r].
b) Else recur for arr[l..mid]
you can watch this too
https://www.youtube.com/watch?v=QOVBnzPgFYY