Microsoft Interview Question

Challenging algorithm question.