Python3 program to implement the above approach
inf = 10 ** 18 NEW_LINE def firstOccurance ( numbers , length , searchnum ) : NEW_LINE INDENT answer = - 1 NEW_LINE start = 0 NEW_LINE end = length - 1 NEW_LINE while start <= end : NEW_LINE INDENT middle = ( start + end ) // 2 NEW_LINE if numbers [ middle ] == searchnum : NEW_LINE INDENT answer = middle NEW_LINE end = middle - 1 NEW_LINE DEDENT elif numbers [ middle ] > searchnum : NEW_LINE INDENT end = middle - 1 NEW_LINE DEDENT else : NEW_LINE INDENT start = middle + 1 NEW_LINE DEDENT DEDENT return answer NEW_LINE DEDENT