Find Root IDs and Paths
Zip interview questions · Medium · Coding round · reported 6× · 6 tests
You are given a collection of blocks. Each block has a unique id and an optional
parentId.
A block counts as a root if either:
- its
parentIdisnull, or - its
parentIdnames an id that no block in the input has.
Implement both parts of the prompt:
- Return all root ids in input order.
- For a given
targetId, list the ids on the chain that starts at its root and ends at the target.
Run your code with Ctrl+Enter to see results.