Amazon Interview Question

asked on leetcode no between 39