← Questions
Block tree with add, delete subtree and render
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A document is an ordered forest of blocks, each with an id and some text. Implement:
-
add(id, parent_id, text): add a block as the last child of its parent, or as the last top-level block when it has no parent. -
delete(id): remove the block and everything nested under it. -
render(): return the document in pre-order, one line per block showing its depth, id and text, with siblings kept in the order they were added.
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
