Search an element in given N ranges | Function to return the index of the range in which K lies and uses linear search ; Iterate and find the element ; If K lies in the current range ; K doesn 't lie in any of the  given ranges ; Driver code
def findNumber ( a , n , K ) : NEW_LINE INDENT for i in range ( 0 , n , 1 ) : NEW_LINE INDENT if ( K >= a [ i ] [ 0 ] and K <= a [ i ] [ 1 ] ) : NEW_LINE INDENT return i NEW_LINE DEDENT DEDENT return - 1 NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = [ [ 1 , 3 ] , [ 4 , 7 ] , [ 8 , 11 ] ] NEW_LINE n = len ( a ) NEW_LINE k = 6 NEW_LINE index = findNumber ( a , n , k ) NEW_LINE if ( index != - 1 ) : NEW_LINE INDENT print ( index , end = " " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( - 1 , end = " " ) NEW_LINE DEDENT DEDENT