McKinsey & Company interview question

algorithm question, all not hard