Turing Interview Question

They provide some of code to solve