educative.io

Educative

Doubt in the iterative solution provided by author

Question: Search a Rotated Array

In the iterative solution provided by author, what is the significance of this if condition

else if (arr[start] <= arr[mid] && arr[mid] <= arr[end] && key > arr[end])
start = mid + 1;

image

Please provide an test case or example to understand this condition

I agree with you.

This condition does not exist in the recursive solution. This condition means if the range from start to end is sorted and the key is not in this range, then we should simply return -1.