Pergunta de entrevista da empresa Flatiron Health

Design an algorithm to solve this problem.