TL;DR
- Trees show up in UI hierarchies, menus, comments, org charts, and document structure.
- I practice both DFS and BFS so I can switch based on the kind of answer I need.
- The main signals are hierarchy, parent/child relationships, and path accumulation.
Context
Frontend developers work with trees constantly, even if they do not call them trees: React component structure, navigation trees, JSON schemas, nested comments, folder explorers, and rich text nodes.
The Approach
Practice these 10 medium-level questions:
- Maximum Depth of Binary Tree — DFS depth baseline.
- Binary Tree Level Order Traversal — BFS queue pattern.
- Validate Binary Search Tree — boundary propagation.
- Lowest Common Ancestor — recurse or parent mapping.
- Right Side View — level-based visibility.
- Path Sum II — accumulate path state and clone at leaves.
- Serialize and Deserialize Tree — stable shape encoding.
- Build Tree From Flat Menu Items — parent/child linking by ID.
- Compare Two Trees for Structural Equality — recursive mirror check.
- Flatten Tree to Linked List Order — preorder restructuring.
Try it in the browser
Browser Practice
Tree practice: level-order traversal
Implement solve(root) and return values level by level. Each node has the shape { value, left, right }.
Sample Tests
1 checks
Function name:
solveBest for JavaScript / TypeScript / JSON practice snippets.Monospace editorRuns in browser sandbox
Trade-offs
- DFS tends to be simpler to write recursively, but BFS can be cleaner when the problem is level-oriented.
- Tree building from flat data is practical, but it depends heavily on the quality of the input constraints.
References
- Related: Coding Practice: Recursion and Backtracking
- Related: Coding Practice: Graphs