Unable to understand the answer of Q7

In Q7, lower_bound(key) is asked which means an iterator to the value which is greater than or equal to key. Here, key=15 and there is no element greater than or equal to 15, so it will point to s.end(). But here ans is coming 6. Please explain!

hi @ankitsinghix05
kindly send the snapshot of the ques u are referring to…

hi @ankitsinghix05
The set::lower_bound() is a built-in function in C++ STL which returns an iterator pointing to the element in the container which is equivalent to k passed in the parameter. In case k is not present in the set container, the function returns an iterator pointing to the immediate next element which is just greater than k. If the key passed in the parameter exceeds the maximum value in the container, then the iterator returned points to the element beyond last element in the set container that is set.end().

@Vaibhav277 In the question above, the key=15 exceeds the maximum value of the set, so it will return set.end() iterator. But, *set.end() is given as 6 for the answer. Please explain how this can come with respect to this question specifically.

hi @ankitsinghix05
the ans uploaded for this ques is wrong… i will inform the team… don’t worry move ahead with other questions…

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.