Uber | Phone screen | Block dependencies

A machine consists of list of blocks that you need to assemble in order. Each block has zero or more dependencies on another block. For example, if block B has a dependency on block A, then A must be assembled before B. In this problem, you are given a list of blocks along with their list of dependencies, and your goal should be to print a valid order to assemble the blocks.

Example:

M -> []
N -> [M]
O -> [M]
P -> [N,0]

Output: Either [M,O,N,P] or [M,N,O,P] would work.

This question is on similar lines: https://leetcode.com/problems/course-schedule-ii

Comments (4)