First and last occurrence

In a given array, to find the first and last occurrence, we can use the following approaches:

  1. Binary Search only
  2. Binary Search, lower_bound and upper_bound

I wanted to know, which is more efficient?

hello @gaurisha

time complexity will remain O(log(n) ) in all the approaches.
so feel free to use ur own binary search function , or inbuilt lower bound,upperbound

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.