Pivot element regarding doubt

int findPivot(int arr[], int low, int high)
{
// base cases
if (high < low) return -1;
if (high == low) return low;

int mid = (low + high)/2; /low + (high - low)/2;/
if (mid < high && arr[mid] > arr[mid + 1])
return mid;

if (mid > low && arr[mid] < arr[mid - 1])
return (mid-1);

if (arr[low] >= arr[mid])
return findPivot(arr, low, mid-1);

return findPivot(arr, mid + 1, high);
}
this code is from geeks in this in first and second conditions mid < high && arr[mid] > arr[mid + 1])
mid<high is not required without this im getting ans so why its there

@deepakjumani09
mid < high should be there because we want to access arr[mid+1] .

and we can access arr[mid+1] only when mid+1 is a valid index .
and for valid index mid+1<=high which can also be written as mid < high

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.