Question related to stacks

question : https://www.hackerrank.com/contests/smart-interviews/challenges/si-changing-directories/problem
my approach: https://pastebin.com/UxMcPy18
Verdict : WA
Can someone help me figure out my mistake and also tell me if i can optimise further?

question dosen’t open up.404 error

oh sorry.
https://pastebin.com/KaJHR1q7