Amazon interview question

Two programming questions (data structure and algorithm)