Amazon Interview Question

Leet code Medium problem and Hard Problem