Problem, as an interviewer would state it: "Given a DOM node, compute the maximum depth of the element tree rooted at it — a leaf counts as depth 1."
Examples:
<div id="root"><div><span>...</span><div><p>deep</p></div></div></div>
maxDepth(root) -> 4
Clarifying questions expected:
- Does a leaf (no element children) count as depth 1 or depth 0?
- Should text/comment nodes count toward depth at all, or only real element children?
- Is the input guaranteed to be a genuine tree (no cycles), the way a real DOM always is?
Code / implementation expected: Yes — real, direct proof against a real jsdom tree with a known shape that the computed depth is correct at multiple points in the tree, not just at the root.