Google Interview Question

They asked a medium LC question + followups