Amazon Interview Question

dsa, 2 questions, one on stack and one on graphs