Microsoft Interview Question

There was a hard puzzle given to solve.