Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Clear is this Interview Question? [closed]

Tags:

java

We are interviewing for a Senior Java Development Role and all three people that we have asked to complete this question gave us the same incorrect answer. The question was done before the interview so they had a lot of time. Their solutions seemed to sort the input by parentId and then childId instead of creating a tree and from the input and then traversing the tree to find the correct order. Is the question not clear enough?

Question:

The following is a simple skills and presentation test for the Java Developer role which must be completed before the telephone interview.

REQUIRED:

  1. JUnit Test

  2. Implementation of NodeSorter interface

QUESTION:

We have a Java object that looks something like this:

public class Node {

    public int id;
    public Integer parentId;

    public Node(int id, Integer parentId) {
        this.id = id;
        this.parentId = parentId;
    }
}

For example the following list of Node(s) might be displayed graphically as:

Node (id: 1, parentId: null), Node (id: 2, parentId: 1), Node(id: 3, parentId: 1), Node(id: 4, parentId: 2), Node(id: 5, parentId: 3)

              Node (id: 1)
             /            \
            /              \
           /                \
          /                  \
      Node (id: 2)         Node (id : 3)
         /                    \
        /                      \
       /                        \
      /                          \
  Node (id: 4)                 Node (id : 5)

Assumptions:

  1. There will be always at least one Node

  2. There will be one and only one Node with a null parentId

  3. Every Node will have a valid parentId except for the Node which has a null parentId

Requirements:

  1. Write a class that implements the following interface that will receive a List of Node(s) and order them from top to bottom (Nodes that are higher in the tree must be before the nodes lower in the tree. Eg. Node 1 on the top of the tree must be before node 4 which is on the bottom of the tree). Nodes on the same level will be in order of their id so the Node with id=2 will appear before the node with id=3 in the diagram above.

Interface:

    public interface NodeSorter {
        public List<Node> sort(List<Node> unSortedNodes);
    }

Test Data:

Test Case 1:


Diagram of Input:

              Node (id: 1)
             /            \
            /              \
           /                \
          /                  \
      Node (id: 2)   Node (id : 3)
         /                    \
        /                      \
       /                        \
      /                          \
  Node (id: 4)           Node (id : 5)

Input: Node (id: 2, parentId: 1), Node(id: 4, parentId: 2), Node (id: 1, parentId: null), Node(id: 3, parentId: 1), Node(id: 5, parentId: 3)

Output: Node (id: 1, parentId: null), Node (id: 2, parentId: 1), Node(id: 3, parentId: 1), Node(id: 4, parentId: 2), Node(id: 5, parentId: 3)

Test Case 2:


Diagram of Input:

              Node (id: 1)    
             /            \
            /              \
           /                \
          /                  \
      Node (id: 5)   Node (id : 2)
         /                    \
        /                      \
       /                        \    
      /                          \
  Node (id: 4)           Node (id : 3)

Input: Node (id: 5, parentId: 1), Node(id: 4, parentId: 5), Node (id: 1, parentId: null), Node(id: 3, parentId: 2), Node(id: 2, parentId: 1)

Output: Node (id: 1, parentId: null), Node (id: 2, parentId: 1), Node(id: 5, parentId: 1), Node(id: 3, parentId: 2), Node(id: 4, parentId: 5)

like image 584
benmmurphy Avatar asked Mar 03 '10 16:03

benmmurphy


People also ask

How the interview is closed?

"I am grateful for interviewing with you today. You have given me a clear overview of the position. I think my experience and accomplishments can provide value to the organization. Is there anything else you need to confirm if I am the right candidate for this position?"

What is a closed question in an interview?

Closed interview questions limit the respondent's options. The examples were selected from different interviews and are not shown in any particular order. A closed question limits the response available to the interviewee. You may be familiar with closed questions through multiple-choice exams in college.

How does an interviewer close an interview?

Explain the next step in the process, including whether there will be further interviews, when you will make your decision, and how the candidate will be informed of your decision. Thank the candidate for interviewing for the position. Complete your notes and/or rating sheets immediately; don't rely on your memory.


2 Answers

I would say that this is pretty darn unclear. You want an unsorted list for input, and a sorted list as output.

Each item in the output list is a tree-node, but there is no balance enforced on the tree. Couldn't the user just read in the values for all the nodes, sort them, and then loop over the sorted values creating new nodes, each of which point at the previous node, and essentially be done...they've created a grossly unbalanced tree (no branches), but who cares?

That seems correct to me, but if I was interviewing I would not be very happy with this answer, because I would be wondering why the tree was there at all.

Nothing in this question indicates to me that I should do anything like what you're suggesting: "creating a tree and from the input and then traversing the tree to find the correct order."

like image 152
Beska Avatar answered Oct 24 '22 10:10

Beska


Honestly, the question seems pretty clear to me.

Have you tried asking them why they chose to sort by list ID and then node ID? Did they think that solved the problem? If so, what is their reaction when confronted with input for which it doesn't work?

Even if they didn't answer the question correctly, by asking them these questions you can both learn more about them and understand what in your question isn't clear enough.

like image 44
Edan Maor Avatar answered Oct 24 '22 10:10

Edan Maor