Amazon Interview Question

Data structures and algorithms problem