We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
For my solution, the problem statement requires some clarification.
A leaf node has only 1 edge.
You are constructing an undirected graph.
For an edge (u,v), most of the time u is the parent and v is the child, however, the order can be (v,u). That can happen when v is a child with a known depth and u has not had a depth assigned. -- This is the magic. Yes, a very unorthodox way to construct a graph.
You may need to have multiple passes through the edges to construct the depth array.
Use the depth array to determine if you call addChild.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Java Visitor Pattern
You are viewing a single comment's thread. Return to all comments →
For my solution, the problem statement requires some clarification.