Code not passing test case 1

You try for this input
3
3 1 2
3
Its Correct output is: 0
And Your Code’s output is: -1

your logic is wrong
1.Find middle point mid = (l + h)/2
2.If the key is present at the middle point, return mid.
3.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]
4. 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]


you can see this

yes i forgot that the array is unsorted

Please mark your doubts as resolved in your course’s. and please rate your experience here