Amazon interview question

Leet code Medium problem and Hard Problem