Construct N-ary tree from given parent-child relation and Traversal
Anonymous User
1870

This was asked at a phone interview for Software Engineering 3+ years experience at Clari. How long do you think it would take to solve this problem completely with absolutely no interaction from interviewer?

Problem statement :
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)