When we call binary search in main we pass parameters as (array,0,n-1,key) so why end =n is giving wrong answer and end =n-1 giving right

Hello @hrishikeshjanjal,

if you’ll pass n, then a[n] would be used in the binary search which is a junk value.
This creates an error in the answer.

Thus, passing n-1 eliminates this error.

Hope, this would help.
Give a like, if you are satisfied.

1 Like