SnowFlake Interview Experience - Backend engineer Interview
Anonymous User
470

Question 1
A forest is represented as a list of integers, where each element stores the index of its parent node.

Rules:

1.⁠ ⁠Each node stores its parent’s index in the list.
2.⁠ ⁠For a root node, the parent index is the node’s own index.
3.⁠ ⁠For any node at index i, its parent index satisfies:

There are no NULL or None values in the list, and the input is always valid.

Example

input: [0, 0, 1, 1, 2]

Visualization:
0 1 3 4
X -> x -> x -> X
|
2
x

Please write a function that removes a node from the forest. Note that both the input and output list should satisfy all 3 constraints.

Question 2

You have an N-ary tree (each node can have zero or more children).

The only thing that makes this tree special is that it is distributed —
you can assume that each node runs as a separate process living on a
totally separate host, and the only way these nodes can communicate
is via asynchronous message passing.

Each node has a unique ID.

Each node has a list of the node IDs of its children.

There is a sendAsync method that is provided for you that allows you
to dispatch a message to another node.

When a node receives a message that was sent to it, its receive
method will be called, indicating which node sent the message
and the message itself.

Question:
Count the number of nodes in the tree and print the result at
the root node.

Given a tree of nodes, like so:

    1
  / | \
 2  3  6
/ \  |

4 5 7

Output:
7

Comments (1)