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.
1) You definitely need to add the reverse edges too because the graph is an undirected graph (even though it's a little unclear from the problem statement). Not adding the reverse edges would mean you are not creating the intended graph so you will get wrong results.
2) If you want to do grandChildren.isEmpty(), it might be the case that grandChildren is null, and that will give a null pointer exception. For this reason, we first make sure that grandChildren != null before using the dot (.) operator on it.
Java Visitor Pattern
You are viewing a single comment's thread. Return to all comments →
1) You definitely need to add the reverse edges too because the graph is an undirected graph (even though it's a little unclear from the problem statement). Not adding the reverse edges would mean you are not creating the intended graph so you will get wrong results.
2) If you want to do grandChildren.isEmpty(), it might be the case that grandChildren is null, and that will give a null pointer exception. For this reason, we first make sure that grandChildren != null before using the dot (.) operator on it.
HackerRank solutions.