Shows time limit exceeded ! using binary search will help?

Kunal, i would suggest you to do this question using binary search only, since N is of large order, so time complexity will be less.