human
Count of packets placed in each box after performing given operations | Function to print final array after performing all the operations.
Initialize variables.
Traverse through all operations.
Operation Type.
Move left.
Move right.
Pick a packet.
Drop a packet.
Exit.
Print final array.
Driver Code.
Given capacity.
Given array with initial values.
Array size.
Operations.
Number of operations.
Function call"
Solution in Python:
assistant
#Here is code to count of packets placed in each box after performing given operations and the other steps required.
 def printFinalArray ( a , n , operations , p , capacity ) :
	curr = 0
	picked = False
	for i in range ( p ) :
		s = operations [ i ]
		flag = False
		if ( curr != 0 ) :
			curr -= 1
			break
		if ( curr != n - 1 ) :
			curr += 1
			break
		if ( picked == False and a [ curr ] != 0 ) :
			picked = True
			a [ curr ] -= 1
			break
		if ( picked == True and a [ curr ] != capacity ) :
			picked = False
			a [ curr ] += 1
			break
		else :
			flag = True
		if ( flag == True ) :
			break
	for i in range ( n ) :
		print ( a [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
	capacity = 5
	a = [ 2 , 5 , 2 ]
	N = len ( a )
	operations = [ 3 , 2 , 4 , 1 , 4 , 5 ]
	M = len ( operations )
	printFinalArray ( a , N , operations , M , capacity )