Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

search a number in 2d sorted

def find_in_sorted_mat(mat, N,M,find_element):
    for k in range(len(find_element)):
        X = find_element[k]
        notFound = True
        R = M-1
        L = 0
        while L>-1 and R>-1 and L<N and R<M:
            if mat[L][R] == X:
                print(L,R)
                notFound = False
                break
            elif mat[L][R]>X:
                R = R-1
            else:
                L = L+1
        if notFound:
            print(-1)
 
PREVIOUS NEXT
Tagged: #search #number #sorted
ADD COMMENT
Topic
Name
1+8 =