Prompt 1
Traverse and transform a nested navigation tree
Given nested navigation data, find or transform matching nodes while preserving the required order and returning a predictable result for missing paths.
What this measures
Tree traversal, complexity analysis, JavaScript data modeling, and care around mutation and unusually deep input.
Clarify first
- Ask whether the tree can be empty, malformed, extremely deep, or cyclic, and whether order must be preserved.
- Confirm whether the transformation should mutate the input or return new objects along changed paths.
Strong answer should cover
- Choose depth-first or breadth-first traversal deliberately and explain the trade-off.
- State O(n) time and account for recursion depth or an explicit stack.
- Preserve stable ordering and define the missing-node result.
- Test empty, single-node, deeply nested, duplicate-id, and malformed inputs.
Common miss: Assuming a fixed nesting depth or mutating shared input without making that contract explicit.