Amazon Interview Question

solve a leetcode eays problem