Algorithm · Oracle · Medium
Requirements Given the roots of two N-ary trees, decide whether the trees match exactly in both layout and stored values. Implement the judged function: In a recursive approach, first examine the two current nodes and then compare corresponding children from their child lists in left-to-right order. Follow-up: write an iterative alternative that uses a stack or queue to traverse the two trees together. Examples Input: root1 = 4(7, 9(2)), root2 = 4(7, 9(2)) Output: true…
Checking your access…