Amazon interview question

2 medium to hard DSA Questions.