← Back
00:00

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 parentId is null, or
  • its parentId names an id that no block in the input has.

Implement both parts of the prompt:

  1. Return all root ids in input order.
  2. For a given targetId, list the ids on the chain that starts at its root and ends at the target.
Idle