human
Given a Boolean Matrix , find k such that all elements in k ' th ▁ row ▁ are ▁ 0 ▁ and ▁ k ' th column are 1. | Python program to find k such that all elements in k ' th ▁ row ▁ ▁ ▁ are ▁ 0 ▁ and ▁ k ' th column are 1.
start from top right - most corner.
initialise result.
find the index ( This loop runs at most 2 n times , we either increment row number or decrement column number ).
if the current element is 0 , then this row may be a solution.
check for all the elements in this row.
if all values are 0 , update result as row number.
if found a 1 in current row , the row can 't be a   solution, increment row number.
if the current element is 1.
check for all the elements in this column.
if all elements are 1 , update result as col number.
if found a 0 in current column , the column can 't be a  solution, decrement column number.
if we couldn ' t ▁ find ▁ result ▁ in ▁ above ▁ loop , ▁ result ▁ doesn ' t exist.
check if the above computed res value is valid.
test find ( arr ) function"
Solution in Python:

=====
What is a code to given a Boolean Matrix , find k such that all elements in k ' th ▁ row ▁ are ▁ 0 ▁ and ▁ k ' th column are 1?
assistant
#Here is code to given a Boolean Matrix , find k such that all elements in k ' th ▁ row ▁ are ▁ 0 ▁ and ▁ k ' th column are 1.
 def find ( arr ) :
	n = len ( arr )
	i = 0
	j = n - 1
	res = - 1
	while i < n and j >= 0 :
		if arr [ i ] [ j ] == 0 :
			while j >= 0 and ( arr [ i ] [ j ] == 0 or i == j ) :
				j -= 1
			if j == - 1 :
				res = i
				break
			else : i += 1
		else :
			while i < n and ( arr [ i ] [ j ] == 1 or i == j ) :
				i += 1
			if i == n :
				res = j
				break
			else : j -= 1
	if res == - 1 :
		return res
	for i in range ( 0 , n ) :
		if res != i and arr [ i ] [ res ] != 1 :
			return - 1
	for j in range ( 0 , j ) :
		if res != j and arr [ res ] [ j ] != 0 :
			return - 1 ;
	return res ;
arr = [ [ 0 , 0 , 1 , 1 , 0 ] , [ 0 , 0 , 0 , 1 , 0 ] , [ 1 , 1 , 1 , 1 , 0 ] , [ 0 , 0 , 0 , 0 , 0 ] , [ 1 , 1 , 1 , 1 , 1 ] ]
print find ( arr )