Thoughtworks interview question

Some hard Puzzles were asked