Exploring a possible solution


Now that we understand the limitations of standard binary search for locating the first occurrence of a value, we need a slightly refined approach. Simply finding any student with a score of 85 is not enough. We need to identify the first student with that score in the sorted list.

Lower bound

The lower-bound algorithm is a popular variant of binary search. It aims to find the index of the first element in a sorted array greater than or equal to the target.

  • If multiple values equal the target, it returns the index of the first occurrence
  • If the target is not present, it returns the index of the smallest element greater than the target
  • If no such element exists, it returns the size of the array.

Liking the course? Check our discounted plans to continue learning.