Search insert position of K in a sorted array | Function to find insert position of K ; Traverse the array ; If K is found ; If arr [ i ] exceeds K ; If all array elements are smaller ; Driver Code
def find_index ( arr , n , K ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT if arr [ i ] == K : NEW_LINE INDENT return i NEW_LINE DEDENT elif arr [ i ] > K : NEW_LINE INDENT return i NEW_LINE DEDENT DEDENT return n NEW_LINE DEDENT arr = [ 1 , 3 , 5 , 6 ] NEW_LINE n = len ( arr ) NEW_LINE K = 2 NEW_LINE print ( find_index ( arr , n , K ) ) NEW_LINE