The lower_bound() and upper_bound() functions, by default works on non-decreasing array. The lower_bound() function finds iterator of first element that does not compare less to given element. The upper_bound() function returns iterator to the first element that is greater.
Given an array converting this to a non-increasing vector, applying the std:: upper_bound and std:: lower_bound function to the vector
For array sorted in a non-increasing array, lower_bound() finds iterator to the first element that does not compare greater than to given element. upper_bound() finds iterator to the first element that is smaller than the given element. We use greater() for this purpose.
lower_bound at position 5 upper_bound at position 4
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.