DoorDash Interview Question

Solve to compare two n-ary tree