Nested Todo List
Updated
Problem statement
Process operations against an initially empty nested todo list. Items form an ordered forest.
["ADD", id, parentId, text]adds a pending item. AparentIdof-makes it a root; otherwise it becomes the newest child of that parent.["TOGGLE", id]switches that item betweenPENDINGandDONE. Toggling one item does not change descendants or ancestors.["GET", id]returnsid|parentId|status|text.["RENDER"]returns every item in preorder. Each line isdepth|id|status|text, roots and siblings retain insertion order, and lines are joined by a newline.
Return the values produced by GET and RENDER operations in order.
Function
runNestedTodoList(operations: String[][]) → String[]Examples
Example 1
operations = [["ADD","1","-","Plan"],["ADD","2","1","Draft"],["ADD","3","1","Review"],["TOGGLE","2"],["GET","2"],["RENDER"]]return = ["2|1|DONE|Draft","0|1|PENDING|Plan\n1|2|DONE|Draft\n1|3|PENDING|Review"]The two children retain insertion order. Toggling item 2 changes only that item.
Constraints
1 <= operations.length <= 20000.- IDs are unique non-empty strings containing neither
|nor whitespace. - Every non-root parent exists before its child is added.
- Every
GETandTOGGLEreferences an existing item. - Text is non-empty and contains neither
|nor a newline. - The total number of rendered item lines is at most
200000.
More Notion interview questions
- Mutable Table AggregationsPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2026
- Block Type with the Most ChildrenPHONE SCREEN · Seen Mar 2026
- Country with the Most EventsPHONE SCREEN · Seen Mar 2026
- Event Type with the Most EventsPHONE SCREEN · Seen Mar 2026
- Most Popular Active Plan for the Top Event TypePHONE SCREEN · Seen Mar 2026
- Page Permission InheritancePHONE SCREEN · ONSITE INTERVIEW · Seen Mar 2026
- Percentage of Blocks Never EditedPHONE SCREEN · Seen Mar 2026
- Text Document HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Mar 2026
- Versioned Document StorePHONE SCREEN · Seen Apr 2025
- Top Error Types in a Time WindowONSITE INTERVIEW · Seen Jun 2026
Similar questions at other companies
- File System Shell CommandsHarvey · ONSITE INTERVIEWHarvey interview questions
- 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
- Workspace File System With Folders and TablesClay · PHONE SCREEN
- Throne Inheritance Without an Initial KingSnowflake · PHONE SCREENSnowflake interview questions
- Render a Comment HierarchyAmazon · ONSITE INTERVIEW
- Nested Recipe Inventory ManagerStackAdapt · PHONE SCREENStackAdapt interview questions
- Render a Stable Comment HierarchyBobyard · PHONE SCREEN
- Delete a Filesystem TreeDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions