← New York Times Interview Insights

New York Times·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Interviewed for a software engineering role at the New York Times. One coding question, pretty focused, nothing too crazy but it tripped me up more than I expected.

Questions Asked (1)

Q1

Given a flat array of objects (each with an id and a parent reference), transform it into a properly nested hierarchical list.

Algorithms & Data StructuresData Modeling
Author's notes

I jumped straight to a recursive solution and it worked but I fumbled explaining the time complexity.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the input format and assumptions (e.g., whether the array is sorted, if parent references are IDs or direct object references, and if there can be multiple roots). Then propose an efficient O(n) solution using a hash map to index nodes by ID, followed by a second pass to link children to parents. Finally, discuss handling edge cases like missing parents, cycles, and multiple roots.

Pro tip: Mention that you'd validate the data for cycles or missing parents before building the tree, and consider whether to mutate the original objects or create new ones to avoid side effects. This shows you think about robustness and production concerns.

1. Clarify requirements and assumptions

Ask about input size, whether parent references are IDs or object pointers, if there can be multiple roots, and if the array is sorted. Confirm the expected output format (e.g., nested objects with children arrays).

2. Design the algorithm

Propose a two-pass approach: first, create a map from ID to node (and initialize children arrays); second, iterate again to attach each node to its parent's children list. Identify root nodes (those with null/undefined parent).

3. Handle edge cases

Discuss what to do if a parent ID doesn't exist (e.g., treat as root or throw error), if there are cycles, or if multiple roots exist. Decide whether to return a single root or an array of roots.

4. Analyze complexity and optimize

State that the solution is O(n) time and O(n) space. Mention that a single-pass approach is possible if nodes are guaranteed to be in topological order, but the two-pass is more robust.

5. Test and validate

Walk through a small example to verify correctness, including edge cases. Suggest writing unit tests for empty input, single node, multiple roots, and deep nesting.

Key Points to Mention

  • Hash map for O(1) lookups to achieve O(n) time complexity
  • Two-pass algorithm: first index nodes, then link children
  • Handling multiple roots and returning an array if necessary
  • Cycle detection to prevent infinite loops
  • Immutability: whether to mutate original objects or create new ones
  • Space-time tradeoff and potential for single-pass if sorted

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