The key idea here is that an item moves from stack1 to stack2 just once in its whole lifetme i.e. its pushed in stack1, gets moved to stack2 and then popped out. There's no going back and forth whatsoever. So it can undergo 4 operations at the most in its life cycle
- (First push) Initial push in stack1 on enqueue
- (First pop) When popped for movement from stack 1 to stack2
- (Second push) When pushed in stack 2 for movement from stack 1 to stack2
- (Second pop) When popped out on dequeue
Let's say each push/pop operation costs $1. So an item would consume $4 right from getting enqueued to getting dequeued. So if you were running this enqueue/dequeue business, your business would break even ($0 profit or loss) if you started charging $4 for each enqueue and dequeue operation. Hence a $4 amortised cost for each enqueue/dequeue combined operation.
Rather if you were running an enqueue only business, you could just charge $1 since you have only 1 push to do and your job is done. Hence a $1 amortised cost for each enqueue operation.
And if you were running a dequeue only business, you would charge $3 for each dequeue operation as you would have to pop twice and push once as described in the steps above. Hence a $3 amortised cost for each dequeue operation.