Can you explain me this code through stack method

I am unable to do it via stack method.

@devfest2021_ca0dcbd15233fafb This video might help :