Amazon Interview Question

1 coding challenge (leetcode easy)