Upper and lower bound

i m not getting logic for -1 please help

I think your code and logic is correct, you were just forgetting the endl in last “-1 -1”. But this code will result in TLE, we can do this question in logn using upper_bound and lower_bound functions.

sir what difference would it make if i do it by function please exlain

Your implementation of function is O(n)
upper_bound and lower_bound will do same thing in O(logn) so they are faster then the function you have created.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.