Amazon Interview Question

Leetcode style coding problem