← bobyard Interview Insights

bobyard·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Bobyard frontend interview, one meaty coding question that covered more ground than I expected. It started looking like a simple sort-and-display task but kept expanding into tree logic and persistent state. Not a bad experience, just caught me underestimating the scope.

Questions Asked (1)

Q1

You're given a flat array of comment objects with fields for id, userId, timestamp, content, and a nullable parentId. Implement the frontend logic to: sort comments by timestamp or userId in either direction, persist the chosen sort settings across page refreshes, reconstruct the nested comment tree from parentId relationships without touching the backend, and filter visible comments by content text so that only matching comments and their full descendant chains are shown.

System DesignAlgorithms & Data StructuresTechnical Trade-offs
Author's notes

This one kept growing.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and edge cases, then outline a modular architecture that separates concerns: sorting, persistence, tree building, and filtering. Walk through each component with concrete data structures and algorithms, emphasizing efficiency and maintainability, and conclude with trade-offs and testing considerations.

Pro tip: Mention that filtering should be applied after building the tree to preserve descendant chains, and use memoization to avoid recomputing the tree on every sort or filter change. Also, persist sort settings using localStorage with a versioned key to handle future changes gracefully.

1. Clarify requirements and constraints

Ask about expected data size, whether sorting should be stable, and if filtering should be case-sensitive. Confirm that persistence is only for sort settings, not the comment data itself.

2. Design data flow and state management

Propose a unidirectional data flow: raw comments -> sorted comments -> tree -> filtered tree. Use a state management approach (e.g., React state/context or Redux) to hold sort settings and derived data.

3. Implement sorting and persistence

Sort the flat array based on timestamp or userId, in ascending or descending order, using a comparator function. Persist the sort field and direction in localStorage, and initialize state from there on page load.

4. Build the nested tree from parentId

Create a map of id to comment object, then iterate to link children to parents. Handle orphaned comments (parentId not found) by either ignoring or treating as roots, and ensure no cycles.

5. Filter and render the tree

Traverse the tree depth-first, including a comment if its content matches or if any descendant matches. Return a new tree with only included nodes, preserving the hierarchy. Render recursively.

Key Points to Mention

  • Use a Map for O(1) lookups when building the tree and filtering.
  • Persist sort settings with localStorage and parse/validate on load.
  • Filtering must include ancestors of matching comments to maintain context.
  • Consider performance: memoize the tree and filtered results, and avoid deep cloning.
  • Handle edge cases: empty array, missing parent, circular references, and large datasets.
  • Discuss trade-offs: client-side vs server-side filtering, and whether to flatten for rendering.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.