In this question I am able to get the approach but in the upper bound the index is always coming one more than the answer i am not able to get it .
Https://ide.codingblocks.com/s/480819
hello @architsuryavanshi
yeah upper bound will return indexx of value which is greater than the key we are searching.
also 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
check this ->
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.