Pergunta de entrevista da empresa Red Hat

Some algorithmic questions. Simple and tricky.