Cover image for Meta
See All Photos


Engaged Employer


Add an Interview

Interview Question

Front End Engineer Interview



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.

Meta Careers

Cover image for Meta

Build for the future with Meta. Meta is building for the future by developing innovative ways to build community and bring people closer...More

  • What We Build
  • Our Actions
  • Our Community
This is the employer's chance to tell you why you should work for them. The information provided is from their perspective.