Amazon Interview Question

They asked to solve a DS Alg problem