MIT interview question

How did you solve this problem?