DoorDash interview question

Solve to compare two n-ary tree