Algorithm · Robinhood · Medium
Given a graph described by a 2D adjacency list, create an independent clone of that graph. Every Node has a val field that uniquely identifies it and a list containing its neighboring nodes. Define Node as having an integer val field and a neighbors list of Node objects. Write a function with the signature cloneGraph(node: Node null) -> Node null that produces a deep copy of the graph. You may assume that node values range from 1 through 100. A node can have zero neighbors…