Pregunta de entrevista de Lyft

Leetcode medium task, same as discussed here