human
Count the number of pop operations on stack to get each element of the array | Function to find the count.
Hashmap to store all the elements which are popped once ..
Check if the number is present in the hashmap Or in other words been popped out from the stack before ..
Keep popping the elements while top is not equal to num.
Pop the top ie . equal to num.
Print the number of elements popped ..
Driver code"
Solution in Python:
assistant
#Here is code to count the number of pop operations on stack to get each element of the array and the other steps required.
 def countEle ( s , a , N ) :
	mp = { }
	for i in range ( 0 , N ) :
		num = a [ i ]
		if num in mp :
			print ( "0" , end = " ▁ " )
		else :
			cnt = 0
			while s [ - 1 ] != num :
				mp [ s . pop ( ) ] = True
				cnt += 1
			s . pop ( )
			cnt += 1
			print ( cnt , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
	N = 5
	s = [ ]
	s . append ( 1 )
	s . append ( 2 )
	s . append ( 3 )
	s . append ( 4 )
	s . append ( 6 )
	a = [ 6 , 3 , 4 , 1 , 2 ]
	countEle ( s , a , N )