one test case failed please elaborate that one here is the code https://ide.codingblocks.com/s/241816
One test case failed
- FInding the Pivot element in the array is of the O(n), so why would you do such a lot of work, if it is so then you can also use Linear Search which will let you find the element in O(n), Where n is the number of elements in the array.
- But You would get TLE as the constraint is quite large.
Here is the Algorithm that will let you find the element in O(log n)
- Find middle point mid = (l + h)/2
- If the key is present at the middle point, return mid.
- Else If arr[l…mid] is sorted
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]
- Else (arr[mid+1…r] must be sorted)
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]