Google Interview Question

4-5 leet code medium - hard