N Array Tree construction and Traversal
Anonymous User
300
May 30, 2020
May 30, 2020

This question was asked at a telephone screen of 1 hour with a company called Clari. How long do you think it would take to solve this full problem with absolutely no interaction from interviewer.

Question:
The Tree and Node class are left blank and you may implement
any constructor, methods, and variables you see fit to solve
the following question parts.
Complete the parts using the following tree.

Desired tree: 0-* children tree
1
-------|------
/ | \
2 3 4
/ \ |
5 6 7

Interview parts:
1.) Build tree from mock CSV file.
2.) Print all node ids in BFS order
3.) Print all node ids with their respective children
EX: 1 - 2,3,4 \n 2 - 5,6 \n etc.
4.) Given a node id, find the reporting path of the node to the root
EX: input - 7, output - 4,1

import java.io.*;
import java.util.*;

class Solution {
  static final String[] CSV = new String[] {
    // ID, PARENTID, NAME
    "4,1,FOUR",
    "6,2,SIX",
    "1,,ONE",
    "2,1,TWO",
    "5,2,FIVE",
    "7,4,SEVEN",
    "3,1,THREE"
  };
  
  static class Tree {
    
  }
  
  static class Node {
    
  }
  
  public static void main(final String[] args) {
    final Tree t = new Tree();

    
    
    
  }
  
}
Comments (1)