Render a Nested Block Tree as a Numbered Outline

Last updated: November 29, 2026

Quick Overview

Given a page stored as a tree of typed blocks (numbered items, bullets, to-dos, plain text), produce the plain-text outline a user would see, with numbering that restarts whenever a run of numbered siblings is broken.

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

0

0

0 solved


Given a page stored as a tree of typed blocks (numbered items, bullets, to-dos, plain text), produce the plain-text outline a user would see, with numbering that restarts whenever a run of numbered siblings is broken.

Notion stores every paragraph, list item and to-do as a block with a parent and an ordered list of child ids, so export to Markdown or plain text is a tree walk. A phone screen like this checks clean recursion over the block model and attention to the small rendering rules users notice, such as when list numbering restarts.

What the Interviewer Expects
  • Clarify the block schema and which types carry markers
  • Walk children in stored order with correct indentation per depth
  • Keep a per-sibling-run counter that resets when a non-numbered block appears
  • Handle empty pages and nested numbered lists that start again at 1
  • State O(n) time and discuss recursion depth for deeply nested pages
Key Topics to Cover
Tree traversal
DFS
Block data model
Ordered children
String building
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 render to Markdown instead, including toggles and code blocks?
  • A page has 50,000 nested blocks and the recursion overflows. How do you rewrite it?
  • Some child ids point to blocks the user cannot see. How should the output change?
  • How would you stream the output for a very large page instead of building one string?
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 a map id -> {type, text, children} and a root page id. Output is one line per descendant block, indented two spaces per depth. Markers: numbered gets k. where k counts consecutive numbe...

High-Level Design

Depth-first, pre-order traversal. For each parent, iterate its children in stored order and keep one counter local to that parent, so nested lists get their own numbering. Emit the line for a child, t...


Submit Your Answer
Markdown supported

Related Questions