FastPrepJSON Block Tree Operations
Problems/JSON Block Tree Operations

JSON Block Tree Operations

Notion logoNotion● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: An onsite report describes JSON shaped like nested Notion blocks. Candidates add and delete nodes, and walk through or render the structure while handling edge cases. We chose how operations and rendering are written, since the report leaves out the interface details.

Our version is about 95% the same as the reported question.

Maintain an ordered forest of document blocks. Process these operations:

  • ["ADD", id, parentId, text] adds a block. A parentId of - 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 is depth|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

Notion interview experiences

  • Notion Interviews, Level Not Reported: 20 Experiences
  • Notion Experienced SWE Interviews: 7 Experiences
  • Notion SWE New Grad Interviews: 3 Experiences
  • Notion SWE Intern Interviews and Debugging Round: 6 Experiences
  • Notion New Grad SWE Onsite Invitations: 2 Experiences
All Notion interview questionsSee Notion hiring insights
Saved
class Solution {
    public String[] runJsonBlockTree(String[][] operations) {
        // Write your code here.
    }
}
Checking account…