human
A Binary String Game | Function to return the result of the game.
Length of the string.
List to maintain the lengths of consecutive '1' s in the string.
Variable that keeps a track of the current length of the block of consecutive '1' s.
Adds non - zero lengths.
This takes care of the case when the last character is '1.
Sorts the lengths in descending order.
Scores of the 2 players.
For player 1.
For player 2.
In case of a tie.
Print the result.
Given string S.
Function call"
Solution in Python:
assistant
#Here is code to a Binary String Game and the other steps required.
 def gameMax ( S ) :
	N = len ( S )
	list = [ ]
	one = 0
	for i in range ( N ) :
		if ( S [ i ] == '1' ) :
			one += 1
		else :
			if ( one != 0 ) :
				list . append ( one )
			one = 0
'
	if ( one != 0 ) :
		list . append ( one )
	list . sort ( reverse = True )
	score_1 = 0
	score_2 = 0
	for i in range ( len ( list ) ) :
		if ( list [ i ] % 2 == 1 ) :
			score_1 += list [ i ]
		else :
			score_2 += list [ i ]
	if ( score_1 == score_2 ) :
		return ' - 1'
	if ( score_1 > score_2 ) :
		return " Player ▁ 1"
	else :
		return " Player ▁ 2"
S = "11111101"
print ( gameMax ( S ) )