Amazon interview question

some stack related coding question.