Pergunta de entrevista da empresa BNSF Railway

It was a medium LC problem