You are given the roots of two N‑ary trees, where each tree models a hierarchical label layout similar to HTML elements. Each label can have one of two configurations:
text is empty or null) and acts purely as a container that groups one or more child labels in top‑to‑bottom order.A leaf label is defined as any label that contains a non‑empty string and does not possess any children. Every other label is a structural grouping element; its text should be treated as empty.
Your job is to walk each tree and collect the text values of all leaf labels from top to bottom. Concatenate them in the order they are encountered within the layout.
Return true if the final concatenated strings from the two label structures are identical (same case and character sequence). Return false otherwise.
The label node is represented by the following class:
class HtmlLabel {
String text;
List<HtmlLabel> children;
...
}
Constraints
Example
Input:
> Label 1:
> <root>
> <container>
> <div> "He" </div>
> <div> "llo" </div>
> </container>
> <p> "World" </p>
> </root>
>
> Label 2:
> <root>
> <div> "Hello" </div>
> <container>
> <span> "Wor" </span>
> <span> "ld" </span>
> </container>
> </root>
>
true
First structure leaf labels in order: "He" + "llo" + "World" → "HelloWorld". Second structure leaf labels in order: "Hello" + "Wor" + "ld" → "HelloWorld". The concatenated strings are equal, so the result is true.