Interview Question

Front End Engineer Interview

-London, England, England


Given two identical DOM trees (not the same one), and a node from one of them find the node in the other one.


Interview Answer

1 Answer


const findCorrespondingNode = (rootA, rootB, target) => { // your code here let directions = [] let found = false function findNode(root, target, track){ if(!root) return if(root === target){ directions = [...track] found = true return } for(let i= 0; i <div> <div> <div></div> </div> <div> </div> <div> <div> <p></p> </div> </div> <div> </div>` const B = A.cloneNode(true) const node1 = A.querySelector('#node1') const node2 = A.querySelector('#node2') const node1Target = B.querySelector('#node1') const node2Target = B.querySelector('#node2') console.log(findCorrespondingNode(A, B, node1Target))</div>

My DFS solution on

Add Answers or Comments

To comment on this, Sign In or Sign Up.