human
Find the winner of a game where scores are given as a binary string | function for winner prediction.
increase count.
check losing condition.
check winning condition.
check tie on n - 1 point.
increase count.
check for 2 point lead.
condition of lost.
condition of win.
Driver Code"
Solution in Python:
assistant
#Here is code to find the winner of a game where scores are given as a binary string and the other steps required.
 def predictWinner ( score , n ) :
	count = [ 0 for i in range ( 2 ) ]
	for i in range ( 0 , len ( score ) , 1 ) :
		index = ord ( score [ i ] ) - ord ( '0' )
		count [ index ] += 1
		if ( count [ 0 ] == n and count [ 1 ] < n - 1 ) :
			print ( " GEEKS ▁ lost " , end = " ▁ " )
			return
		if ( count [ 1 ] == n and count [ 0 ] < n - 1 ) :
			print ( " GEEKS ▁ won " , end = " ▁ " )
			return
		if ( count [ 0 ] == n - 1 and count [ 1 ] == n - 1 ) :
			count [ 0 ] = 0
			count [ 1 ] = 0
			break
	i += 1
	for i in range ( i , len ( score ) , 1 ) :
		index = ord ( score [ i ] ) - ord ( '0' )
		count [ index ] += 1
		if ( abs ( count [ 0 ] - count [ 1 ] ) == 2 ) :
			if ( count [ 0 ] > count [ 1 ] ) :
				print ( " GEEKS ▁ lost " , end = " ▁ " )
			else :
				print ( " GEEKS ▁ won " , end = " ▁ " ) ;
			return
if __name__ == ' _ _ main _ _ ' :
	score = "1001010101111011101111"
	n = 15
	predictWinner ( score , n )