Pergunta de entrevista da empresa Toast Inc

Given a tree-like graph, code a function to create a hashset with roots as the keys and an array of leaf nodes of that root as the value.