Understanding the problem
Even after learning about binary search and lower bound, there are situations where locating the first occurrence of a value is not enough. Sometimes we need to find the last occurrence of a value in a sorted list, which neither standard binary search nor lower-bound directly provides.
Example
Imagine you are a school teacher with a sorted list of thousands of students. Several students scored 85 marks, and you want to identify the student who scored just higher than 85, i.e., the first student in the list with a score strictly greater than 85.
Liking the course? Check our discounted plans to continue learning.