HackerRank problems and doubt


This problem is under the the filter search ,But I cannot makeout how to apply binary search on it.please help.

SIr I am a begginner and am getting stuck on many problems .How nmany minimum roblrms should I practice per day so that within 6 month I am very good as competitive programming and can increase my rating on the codechef and codeforces.

I think a lot but did not get the binary search solution for this problem

it can be solved using BFS (breath first search)
here is my code

Can you please show me the working and explanation.

i have shared the whole code