You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mani Bhushan edited this page Aug 14, 2016
·
16 revisions
Question:
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.
High Level Approach:
Do a breadth first search of the input graph and while cloning individual graph nodes, do check if you have already created that graph node or not. We can use a hashmap to remind ourselves if we have already created a particular graph node or not.
Time Complexity: O(V + E)
Space Complexity: O(V + E)