Pergunta de entrevista da empresa McKinsey & Company

algorithm question, all not hard