HashedIn by Deloitte Interview Question

question related to Tree and graph data structure