McKinsey & Company Interview Question

algorithm question, all not hard