facebook logo
Facebook· Software Engineer E5

📌 Facebook | E5 | Bay Area | Phone Screen

Result
Offer
Location
Bay Area
Posted
13 Mar 2021
326 reads

Summary

I successfully navigated my phone screen interview at Facebook for an E5 role in the Bay Area, demonstrating optimal solutions for two coding problems and ultimately receiving an offer.

How it went

I had my Facebook E5 phone screen interview, which lasted for 45 minutes. We started with a brief 3-5 minute introduction. The interviewer then clarified that the majority of the time would be dedicated to problem-solving, reserving the last 5 minutes for my questions.

The first question I encountered was Add Binary. Having practiced this problem before, I immediately explained the optimal approach, achieving a time complexity of O(max(l1, l2)). The interviewer was satisfied with my algorithm, and I quickly proceeded to code the solution in Java. After coding, I walked through my solution with a few examples. This entire segment, including discussion and coding, was completed within 10-15 minutes.

/**
 * Time Complexity: O(max(l1, l2))
 * Space Complexity: O(max(l1, l2))
 * l1 = Length of string A, l2 = Length of string B.
 */
public String addBinary(String a, String b) {
    if (a == null && b == null) {
        return "0";
    }
StringBuilder result = new StringBuilder();

int i = a.length() - 1;
int j = b.length() - 1;
int carry = 0;

while (i >= 0 || j >= 0) {
    int sum = carry;
    if (i >= 0) {
        sum += a.charAt(i) - '0';
        i--;
    }
    if (j >= 0) {
        sum += b.charAt(j) - '0';
        j--;
    }
    result.append(sum % 2);
    carry = sum / 2;
}

if (carry == 1) {
    result.append('1');
}

return result.reverse().toString();

}

Following that, the second question was Merge Intervals. Again, I was familiar with this problem and presented the optimal O(NlogN) approach. Once the interviewer approved the algorithm, I implemented the solution in Java and demonstrated its functionality with test cases. This question took approximately 20-25 minutes to complete.

/**
 * Time Complexity O(N log N)
 * Space Complexity: O(N) (Including the List<int[]> result)
 * N = Length of input array.
 */
public int[][] merge(int[][] intervals) {
    if (intervals == null || intervals.length <= 1) {
        return intervals;
    }
Arrays.sort(intervals, (a, b) -&gt; (a[0] - b[0]));

List&lt;int[]&gt; result = new ArrayList&lt;&gt;();
int start = intervals[0][0];
int end = intervals[0][1];

for (int i = 1; i &lt; intervals.length; i++) {
    if (intervals[i][0] &lt;= end) {
        end = Math.max(end, intervals[i][1]);
    } else {
        result.add(new int[] { start, end });
        start = intervals[i][0];
        end = intervals[i][1];
    }
}

result.add(new int[] { start, end });
return result.toArray(new int[result.size()][2]);

}

With a few minutes remaining, I took the opportunity to ask the interviewer two questions about their current work at Facebook. I was thrilled to later receive a call from the recruiter informing me of positive feedback from the hiring committee and that an offer would be extended.

Questions asked (2)

  1. 01

    Add Binary

    Data Structures & Algorithms · Easy

    Given two binary strings a and b, return their sum as a binary string.

    Open the problem
  2. 02

    Merge Intervals

    Data Structures & Algorithms · Medium

    Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.

    Open the problem

How they prepared

My preparation focused on completing as many LeetCode questions as possible, especially those recently tagged with Facebook. This approach proved highly beneficial, allowing me to solve both interview problems optimally and within the strict time constraints.

Know someone preparing? Send it to them:WhatsAppLinkedInX

Interviewed at Facebook recently?

Write up your rounds while you still remember the questions. It helps the next person more than you would think.

Share your experience
Discussion 0

Questions for the author, or how your own interview compared.

Join the discussion

Sign in with Google to comment or ask the author a question.

No comments yet

Be the first to share your thoughts and start the discussion!