Binary Search (Number of Occurance of a number)


In order to find the number of occurance of a number using binary search, all we have to use is our common sence. We already have the first occurance of a number and the last occurance of the number. All we need to do is find the first occurance say first, last occurance say last and then return last - first + 1.

The code is.