human
Find the person who will finish last | Function to find the person who will finish last.
To keep track of rows and columns having 1.
Available rows and columns.
Minimum number of choices we have.
If number of choices are odd.
P1 will finish last.
Otherwise , P2 will finish last.
Given matrix"
How can the above be solved in Python?
assistant
#Here is code to find the person who will finish last and the other steps required.
 def findLast ( mat ) :
	m = len ( mat )
	n = len ( mat [ 0 ] )
	rows = set ( )
	cols = set ( )
	for i in range ( m ) :
		for j in range ( n ) :
			if mat [ i ] [ j ] :
				rows . add ( i )
				cols . add ( j )
	avRows = m - len ( list ( rows ) )
	avCols = n - len ( list ( cols ) )
	choices = min ( avRows , avCols )
	if choices & 1 :
		print ( ' P1' )
	else :
		print ( ' P2' )
mat = [ [ 1 , 0 , 0 ] , [ 0 , 0 , 0 ] , [ 0 , 0 , 1 ] ]
findLast ( mat )