Pregunta de entrevista de BNSF Railway

It was a medium LC problem