Upper and Lower Bound


Could you point the error(WA)?

hello @diganta_7777

u r assuming that if key is not presnt then it will return end of the array which is wrong.

lower bound return iterator that is greater than or equal to key.
upper bound return iterator that is greater than key.

for ex->
if array is
1 2 3 7 8 9
and key is 4
the lower/upper bound will return iterator of 7 which is clearly not the end of the array.

first use binary search to check wheter key is present or not.
if not present then simply print -1 -1
otherwise use lower bound ,upper bound

So if key is not present, then what does upper_bound return?

I mean will it return the number just greater than the one passed?

…

yeah …

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.