Binary Search (Last Occurance of a number)


In order to find the last occurance of a number, We only require certain modifications in our orignal binary search code. When we find the item, all we need to do is to change the value of start to mid + 1 (instead of break statement), while saving current mid. In this way we will get the last occurance of the number.

The code is.

The link to code