Amazon Interview Question

It was some leet code medium question