Leftmost Column with atleast one 1 in a row | Python3 program to calculate leftmost column having at least a 1 ; Function return leftmost column having at least a 1 ; If current element is 1 decrement column by 1 ; If current element is 0 increment row by 1 ; Driver Code
N = 3 NEW_LINE M = 4 NEW_LINE def findColumn ( mat : list ) -> int : NEW_LINE INDENT row = 0 NEW_LINE col = M - 1 NEW_LINE while row < N and col >= 0 : NEW_LINE INDENT if mat [ row ] [ col ] == 1 : NEW_LINE INDENT col -= 1 NEW_LINE flag = 1 NEW_LINE DEDENT else : NEW_LINE INDENT row += 1 NEW_LINE DEDENT DEDENT col += 1 NEW_LINE if flag : NEW_LINE INDENT return col + 1 NEW_LINE DEDENT else : NEW_LINE INDENT return - 1 NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT mat = [ [ 0 , 0 , 0 , 1 ] , [ 0 , 1 , 1 , 1 ] , [ 0 , 0 , 1 , 1 ] ] NEW_LINE print ( findColumn ( mat ) ) NEW_LINE DEDENT