Deepest Reply Nesting Level in a Docs Comment Thread Tree

Last updated: November 29, 2026

Quick Overview

Comment threads in a document are stored as a binary tree where each node is a comment. Return the number of nodes on the longest path from the root comment down to any leaf.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Comment threads in a document are stored as a binary tree where each node is a comment. Return the number of nodes on the longest path from the root comment down to any leaf.

A warm-up in a Google phone screen, framed around how Google Docs might cap rendering depth for threaded comments. The interviewer checks that you can write clean recursion quickly and then convert it to an iterative version when asked about deep trees.

What the Interviewer Expects
  • Define depth precisely (nodes, not edges) before coding
  • Write the recursive solution in a few lines
  • Offer an iterative BFS or explicit-stack version to avoid recursion limits
  • State O(n) time and O(h) space
  • Handle the empty tree
Key Topics to Cover
binary trees
recursion
breadth-first search
tree height
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you avoid a stack overflow if the thread is a 100,000 node chain?
  • Return the deepest comment itself, not only the depth.
  • What if each node had an arbitrary number of replies instead of two?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input is the root of a binary tree (possibly None). Output is an integer: the count of nodes on the longest root-to-leaf path. An empty tree has depth 0 and a single comment has depth 1. Confirm wit...

High-Level Design

The depth of a tree is 1 plus the larger depth of its two subtrees, which gives a three-line recursion. Because comment chains can be long and Python limits recursion to roughly 1000 frames, I would s...


Submit Your Answer
Markdown supported