Facebook Interviews-3

I used the time between the last round and this round to brush up my coding skills and review a few standard algorithms. I knew that my coding skills were not up to the mark as the interviewer would expect. I was just hoping that I get lucky this time as well and get through to the next round and in the time I get before next interview, I shall work on improving it. Fortunately, I didn’t have to make that effort. So, here goes the description of what transpired in that interview.

I got the call from interviewer at the scheduled time. He introduced himself as Jeffrey and talked about the team he worked in (I remembered the interviewer’s name this time but not the team or what he did). Like the last interview, this time also I was asked to create a document on collabedit.com and share it’s key. After this, he asked me about my work experience and asked me about a situation in work life which I found challenging and how did I go on to face this challenge. He probed me further with similar HR type questions like describe a situation which you showcased your team-player skills. I wasn’t expecting such questions in this interview as I was expecting it to be similar to last round. I tried to answer them as well as I could. He asked me what are the facebook products you like. After I named Facebook news feed, he asked me what feature you would like to add or improve to better the product. This was the last such type of question, before he got down to asking a technical question.

The question was:

In PHP, there is concept of single class inheritance i.e. a new class can extend an existing class. You are given a php source file which contains a few classes defined in it. You have to print the class hierarchy in the given desired format.
For example, classes in php source file are A, B extending A, C extending B, D extending A, E.
The output should look like:

A
        B
               C
        D
E

I said we could use a Tree data structure and do a BFS (Breadth First Search) to print it this way. Then I soon realized that I should use DFS (Depth First Search) instead and told him so. He asked me to go ahead and write down the code on how to parse the php file to get the desired output. I said we can use a left child-right sibling representation for the nodes of tree. I wrote down some code to show how parsing can be done. I could see myself that my code was half-baked. However, he let me off the hook on that code and asked me how to write down the printing function supposing I have constructed the tree and I have the root node. The task was simple for me at that point, write down the depth first search function for a node. But somehow, at that moment I wasn’t thinking in terms of writing a simple recursive solution which could have done it easily. Then, I was thinking in terms of stack-based implementation of DFS. I didn’t realize it at that time that I had to write the DFS not for a general graph, but for a simple tree structure. Hence, there were no complications of maintaining which nodes had already been visited. But I was thinking about how to handle the nodes already been visited while attempting to write the code and hence, the cluttered thought process which resulted in incomplete code in the stipulated time.

The interviewer interrupted me while I was struggling to write clean code, he said since he is running out of time, he asked me to stop writing the code and tried to reassure me by saying that I was on the right track. I too knew, I was on the right track but it was just that I was not using the right mode of transportation. I was trying to sail a ship on the road. He then asked me if I had a question to ask him, I asked him absent-mindedly similar questions that I asked from the HR contact. I don’t remember what he said as I was having a conflicting thought running in my mind. I was thinking whether I should admit or not that I am a bit out of touch with coding. In the end, the confession mindedness prevailed over the practical mindedness.

I said to him that I had a confession to make that I am a bit rusty with coding and that’s why I was struggling to write the code cleanly. I said that I was making efforts at that time to improve upon my coding speed and efficiency. I don’t know what the interviewer would have felt but he agreed that I needed some work to do on my coding speed. Well, I don’t know if my confession played a role in my rejection or was it the inability to give a proper solution to the question that led to my rejection. I believe that it was the latter.

A few days later, I got the email which tried to describe my rejection in the gentlest of words as possible.

Hi Anurag,

Thanks for taking the time to talk on the phone with us. Your background is impressive, and we enjoyed speaking with you.

Unfortunately, we will not be moving forward with you in the interview process at this time. The volume of interviews we’ve been conducting combined with the quality of candidates that we’ve been talking to often forces us to make difficult decisions.
….

Rejections are always hard to handle especially when expectations from self are high based on your own past record. It took me a few days of pep-talk to self to take in the feeling of rejection and be ready to go on about work and self in a normal way. After rejections, one usually has the options of either hitting the bar to drown himself or to raise the bar to perform better. I decided to choose the latter option and I did clear the raised bar (will write about what I meant and how I did it in one of the posts soon).

7 thoughts on “Facebook Interviews-3”

  1. I also gave three fb interviews during placement season. My question were more on stack, trees, LL, strings, etc.(like your 2nd round). Did you specifically mention that your PHP is good and thats why they asked about PHP parsing, or they expect us to know PHP etc.? Better luck next time.

    1. Thanks 🙂
      No, I didn't mention that I was good in PHP and actually I don't think the question was such that it would have required the knowledge of php. This question was more a test of what data structures I used and how did I reduce the problem description to fit a well-known standard algorithm.

      On a side-note, why don't you share your interview experiences by documenting it.

  2. Answer is Definitely DFS & its tough to implement !!! but i am surprised you are not able to solve that ..you could have pinged me dude 🙂 I always happy to help geeks 🙂 Anyways best of luck for next time

    Shashank

    1. I know the answer was DFS and it was not tough to implement if you think recursively.

      Unfortunately, I wasn't thinking about recursion that time 🙁

  3. void printClassInheritance(Node node) {
    printClassInhertianceRecursively(node, 0);
    }

    void printClassInheritanceRecursively(Node node, int distance) {
    if (node == null) return;

    String indentation = "";
    for (int i = 0; i < distance; i++) {
    indentation += "\t";
    }

    System.out.println(indentation + node.getClassName());
    printClassInheritanceRecursively(node.getLeft(), distance + 1);
    printClassInheritanceRecursively(node.getRight(), distance + 1);
    }

  4. So I have some questions about the proposed solution.
    I find that somehow this question is trying to say that Node D, extends both A,E, which does not seem possible is single class inheritance.
    But given the inputs and outputs. I found that using a graph was the better suit, since potentially you may have a class that just sits out lying.

    NodeChar graphCharA = new NodeChar('A');
    NodeChar graphCharB = new NodeChar('B');
    NodeChar graphCharC = new NodeChar('C');
    NodeChar graphCharD = new NodeChar('D');
    NodeChar graphCharE = new NodeChar('E');

    graphCharA.adj.add(graphCharB);
    graphCharB.adj.add(graphCharC);
    graphCharA.adj.add(graphCharD);
    graphCharE.adj.add(graphCharD);

    //Adj is just list of NodeChars.

    pretty print function:
    public void printDFSGraph(NodeChar start, int currentLevel)
    {
    if (start == null)
    {
    return;
    }

    for(int i = 0; i<currentLevel; i++)
    {
    System.out.print("\t");
    }

    System.out.print(start.data);
    System.out.println();
    currentLevel++;
    start.visited = true;

    //Get children of start position
    List childNodes = start.adj;
    for(NodeChar child : childNodes)
    {
    if(child.visited == false)
    {
    printDFSGraph(child, currentLevel);
    }
    }

    }

    output:

    A
    B
    C
    D
    E

Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.