Amazon Interview Question

some stack related coding question.