Red Hat interview question

Some algorithmic questions. Simple and tricky.