Amazon Interview Question

Based on ds and algorithms