Why is it important to check if the key is greater than a[s]?

if (a[mid] > key and key >= a[s])
In this condition we are checking if the key element is less than a[mid] which if true gives us enough information that we need to look that the left of a[mid] i.e.
e = mid - 1;
I don’t understand the necessity of key >= a[s] comparison.

hello @vrnvbhv
consider this case.
4 5 8 2 3

if mid is on 8 and key = 2 ,then going to left will give wrong answer.
this is because in left we have elements raning from 4 to 8 and clearly 2 is not present in them.

thats whys adding this a[s] <= key to make sure that we are going in right direction

Thanks for the testcase, didn’t see that.