JSON Block Tree Operations
Updated
Problem statement
Maintain an ordered forest of document blocks. Process these operations:
["ADD", id, parentId, text]adds a block. AparentIdof-makes it the newest root; otherwise it becomes the newest child of that active parent.["DELETE", id]deletes that block and its entire descendant subtree.["RENDER"]emits every active block in preorder. Each line isdepth|id|text; roots and siblings retain insertion order, and lines are joined by a newline.
Return the values produced by RENDER operations in order.
Function
runJsonBlockTree(operations: String[][]) → String[]Examples
Example 1
operations = [["ADD","a","-","Page"],["ADD","b","a","Heading"],["ADD","c","a","Paragraph"],["ADD","d","b","Text"],["RENDER"],["DELETE","b"],["RENDER"]]return = ["0|a|Page\n1|b|Heading\n2|d|Text\n1|c|Paragraph","0|a|Page\n1|c|Paragraph"]The first render is preorder. Deleting b also removes its descendant d while preserving sibling c.
Constraints
1 <= operations.length <= 20000.- Every added ID is globally unique and is never reused after deletion.
- Every non-root parent is active when its child is added.
- Every deleted ID is active.
- IDs are non-empty ASCII strings containing neither
|nor whitespace. - Text is non-empty and contains neither
|nor a newline. - The total number of rendered block lines is at most
200000.
More Notion interview questions
- Nested Todo ListPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Top Error Types in a Time WindowONSITE INTERVIEW · Seen Jun 2026
- DAG Downstream NodesONSITE INTERVIEW · Seen Apr 2026
- Mutable Table AggregationsPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2026
- Page Permission InheritancePHONE SCREEN · ONSITE INTERVIEW · Seen Mar 2026
- Text Document HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Mar 2026
- Sliding Window MedianONSITE INTERVIEW · Seen Oct 2025
- Task Row ModificationsONSITE INTERVIEW · Seen Oct 2025
- Block Type with the Most ChildrenPHONE SCREEN · Seen Mar 2026
- Country with the Most EventsPHONE SCREEN · Seen Mar 2026
Similar questions at other companies
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- N-ary Index-Path Encoder and DecoderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Serialize and Deserialize an N-Ary TreeUber · ONSITE INTERVIEWUber interview questions
- Render a Comment HierarchyAmazon · ONSITE INTERVIEW
- Delete a Filesystem TreeDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Evaluate a Parsed Expression for Many Values of xGoogle · ONSITE INTERVIEWGoogle interview questions
- In-Memory File System With Directory SizesCapital One · PHONE SCREEN · ONSITE INTERVIEWCapital One interview questions
- N-Ary Tree Codec OperationsLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Dynamic Order-Statistic Binary Search TreeSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Serialize and Deserialize a Binary TreeMicrosoft · ONSITE INTERVIEWMicrosoft interview questions