Am i writing the correct code?

Am i writing the correct code?

you need to use binary search to solve this question, please refer to below given code