Amazon Interview Question

They asked to solve a leet code question.