Sample test case is passed but failing other testcases don't know why?

Can you help me here and tell me what’s wrong with my code and where I went wrong? I’ve checked for other custom inputs I was getting the correct answer.

Here’s the link to my code.

@Udit-Sehra-2366292823468769

You should handle the cases when mid == 0 and mid == n - 1 seperately because when mid == 0, mid - 1 index doesnt exist and when mid == n - 1, mid + 1 index doesn’t exist

I have modified your code and have marked the changes

Let me know if you still need any help.