Pergunta de entrevista da empresa Nutanix

Hard DSA problem which was tree+graph based question.