Pergunta de entrevista da empresa Thoughtworks

The unexpected question was a puzzle to be solved followed by an algorithm for the same.