Pergunta de entrevista da empresa Lyft

Leetcode medium task, same as discussed here