human
Find the winner of game of repeatedly removing the first character to empty given string | Function to find the winner of a game of repeatedly removing the first character to empty a string.
Store characters of each string of the array arr [ ].
Stores count of strings in arr [ ].
Traverse the array arr [ ].
Stores length of current string.
Traverse the string.
Insert arr [ i ] [ j ].
1 st Player starts the game.
Stores the player number for the next turn.
Remove 1 st character of current string.
Update player number for the next turn.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to find the winner of game of repeatedly removing the first character to empty given string and the other steps required.
 def find_Winner ( arr , N ) :
	Q = [ 0 ] * N
	for i in range ( N ) :
		Q [ i ] = [ ]
	M = len ( arr )
	for i in range ( M ) :
		Len = len ( arr [ i ] )
		for j in range ( Len ) :
			Q [ i ] . append ( ord ( arr [ i ] [ j ] ) - 1 )
	player = 0
	while ( len ( Q [ player ] ) > 0 ) :
		nextPlayer = Q [ player ] [ 0 ] - ord ( '0' )
		del Q [ player ] [ 0 ]
		player = nextPlayer
	print ( " Player " , ( player + 1 ) )
N = 3
arr = [ "323" , "2" , "2" ]
find_Winner ( arr , N )