human
Can you provide a code to array element moved by k using single moves and the other steps required given the following:
Array element moved by k using single moves | Python3 code to find winner of game.
if the number of steps is more then n - 1.
initially the best is 0 and no of wins is 0..
traverse through all the numbers.
if the value of array is more then that of previous best.
best is replaced by a [ i ].
if not the first index.
no of wins is 1 now.
if any position has more then k wins then return.
Maximum element will be winner because we move smaller element at end and repeat the process ..
driver code"
Solution in Python:
assistant
#Here is code to array element moved by k using single moves and the other steps required.
 def winner ( a , n , k ) :
	if k >= n - 1 :
		return n
	best = 0
	times = 0
	for i in range ( n ) :
		if a [ i ] > best :
			best = a [ i ]
			if i == True :
				times = 1
		else :
		if times >= k :
			return best
	return best
a = [ 2 , 1 , 3 , 4 , 5 ]
n = len ( a )
k = 2
print ( winner ( a , n , k ) )