Is there any better code for this problem?

this is my code all test cases passed but is there any better code for this problem ??

ha there is one using modified binary search.

ye video dekhlo prateek bhaiya ki samjh aa jayega

thank u bhai once again

:+1::+1::+1::+1::+1::+1: . . . …