Facebook Coding Interview Questions- Find More About It

Facebook, to most of us, is more of a social media application than an actual company. It brings people from every corner of the world closer than we can ever imagine and makes us feel like a family even if we’re 1000 miles apart from each other. So how does it work so flawlessly throughout the day? It’s a question to most technology enthusiasts. Well unlike other companies or MNCs this brand doesn’t have other campuses or branches in different parts of the world. It is just one headquarter and that is in California, New York. Let us know more detail about ‘Facebook Coding Interview Questions’.

Facebook Coding Interview Questions

Facebook Coding Interview Questions

But that doesn’t mean the people working there are limited. Just like their users, their employees also come from all across the globe and they’re among the most technically advanced minds. Natural isn’t it, a huge group of individuals controlling one application day and night is no joke. So what happens inside this one headquarter and how can one ultimately make their way to Facebook. Well, that’s exactly what we’re going to talk about today. So get ready with your notebooks because the upcoming information is going to be very important to each one who’s preparing for the company that makes the building letter of the word ‘FANG’, i.e., Facebook.

Positions and Recruitment Process of Facebook Inc.

Part -1

Like the other companies in IT Sector, Facebook also has the SDE (Software Developing Engineer) and SE (Software Engineer) position for B.Tech and BE students. If a fresher applies, he goes for the SE-1 or SDE-1 position, whereas for the experienced personnel, the positions SE-2, SE-3, and SDE-2, SDE-3 are available depending on their years of work experience and the technologies they’re acquainted with. The recruitment process however is the same irrespective of the position one is applying for. Every process starts with two online tests, one having multiple choice questions and the other having two compulsory coding questions. 

This is to test the Data Structure and Algorithm Knowledge of the candidate. The questions are mostly from the medium to high-level categories and one needs to have a firm grip of Data Structures to completely solve the questions with all the test cases passed.

Part -2

Once these tests are over and the candidate has successfully passed these rounds, the real interviews start. There are usually 4-5 rounds of interviews and each round is customized by the interviewer in the manner that he wants. The first two rounds are verbal coding rounds where the candidate has verbally tested his coding knowledge through questions. He/she doesn’t have to give the proper code but has to logically explain every step of the solution along with the most optimum time and space complexity.

Since this company works on coding, it lays a lot of importance on testing the coding skill of the candidate. After these rounds come to the pre HR and HR rounds. These rounds are based on personality questions and they are important because based on how the candidate answers these questions depends on what impression is being created in the mind of the recruiter.

Today we will be discussing the most commonly asked coding questions in both the written and verbal technical rounds of the interview. Students must know that these questions are not the only options for the recruiters, they keep changing their levels of difficulty. It is advised that the student makes notes and prepares accordingly.

Facebook Coding Interview Questions

The coding round mainly tests the Data Structure and Algorithm knowledge of the candidate. Not just Facebook, majority of the companies offering the role of Software Development Engineer or a Software Engineer, test the DSA intend to test the DSA skills of the candidate thoroughly.

Data Structures is a vast topic and usually has several subparts, which have questions of their own with different difficulty levels. We will start with the various subtopics and move forward with their respective questions. For the solution I’ll be providing the algorithm and explanation and where possible, I’ll try to include the code snippet for the question. The code snippets will be in the Java programming language.

1. Arrays

Shift the zeroes to the end of the array. i.e., to the left
Problem Statement

An array of non-decimal numbers is provided to you. Shift all the occurrences of zero to the left of the series keeping the order of the rest of the array unchanged. For example, if the array looks like {1, 3, 0, 7, 6, 0, 4, 5, 6, 0, 8, 9, 0, 2, 0} the output array should look like {1, 2, 3, 4, 5, 6, 6, 7, 8, 9, 0, 0, 0, 0, 0}. The overall time and space complexities are expected to be Big O(n) and Big O(n) respectively.


Explanation: There are various ways of proceeding with the solution to the given problem. The easiest way has been explained below.

The basic requirements are that there cannot be more than one array otherwise the required time complexity will not be obtained. One way is that the students must use a variable named ‘c’s which will keep a count of the indices of the non-zero elements of the array. Then there can be a loop that runs from the first to the last element of the array. The non-zero elements will be occupying the positions as count c gets incremented by one every time. By the end of the loop, c will have the position of the first zero of the array. Finally, run the loop from this position to the last position and keep inserting the zeroes.

Bring in the intervals that overlap with each other of exclusive and form one complete one.
Problem Statement

A set of randomly distributed intervals will be given to you. The intervals need to be examined and the output should be displayed in such a way that the intervals appear exclusive and different from the rest. For example, if the set of intervals is given to be {{1, 3}, {2, 4}, {6, 9}, {8, 10}}, then there should be two outputs for this particular set. {1, 3}, {2, 4} should display the result as {1, 4}. Similarly, {6, 9}, {8, 10} should display the result as {6, 10}.


Explanation: There are primarily two ways of proceeding with the solution to the given problem, one is the easier approach and the other one is the efficient approach in terms of time and space complexity. The easiest way has been explained below.

Simple Approach

The basic requirements are that there cannot be more than two loops otherwise the required time complexity will not be obtained. The first loop will traverse through all the given intervals and will check for the intervals with similar beginning or endings, if such an interval is obtained then another loop begins which discards the other interval and returns the first one with its ending element swapped with that of the other interval. This method will produce a Big O(n^2) time complexity.

Efficient Approach

The intervals must be sorted because in a sorted series the intervals of the ith term cannot pair up with that of the previous. Hence once the elements are sorted a linear traversal can be performed on them. This approach will be completed in Big O(n log n) time complexity and Big O(1) space complexity.

2. Linked Lists

Perform the addition of given two integers
Problem Statement

Two numbers will be provided not as normal user inputs but will be represented in the form of two separate linked lists. The expected output is another list that will contain the sum of the two numbers. For example, if the first number is 653, it will be represented as 6→5→3. If the second number is 721, it will be represented as 7→2→1. The resultant sum list must return the number 1374 in the format,

1→3→7→ 4.


Explanation: There are various ways of proceeding with the solution to the given problem. The easiest way has been explained below.

The basic requirements are that there cannot be more than two different loops otherwise the required time complexity will not be obtained. One way is that,

First, the students must travel from the first element to the elements of the list and compare the length of the two digits. If either of them is smaller than the first one, the zeros should be added at the beginning of the list to make the calculation simple.

Next, beginning with the first node i.e., the head node, a recursive function is to be called for the upcoming child nodes. This must continue till the end of the two lists.

A new node is created that contains the sum of the lists and returns it to the console.

Perform the merging operation on two linked lists.
Problem Statement

Two separate linked lists will either be provided or the user can hard code it into the code if he/she does not want to accept user input for the same. The resultant list should have these two merged lists and print one complete list in the same order as the two. The lists may either be overlapping or exclusive, the result however should have one list including the spliced portions from the remaining two. For example, if the first list has 1→3→18 and the second list has 2→4→7→22, the expected output should be 1→ 2→ 3→ 4→ 7→ 18→ 22. All the necessary test cases are to be considered.


Explanation: There are various ways of proceeding with the solution to the given problem. The easiest way has been explained below.

The basic requirements are that there cannot be more than one array otherwise the required time complexity will not be obtained. One way is that the students must use a recursive function to help ease the execution of the code. Although recursive functions take up extra space and are compared to iterative solutions, merging problems are solved much faster with these. In the case of codes that require looping or numeric calculations, recursive codes are less efficient compared to iterative solutions, however here we can move forward with the former. There is no issue of stack piling and occupancy is minimal.

3. Trees

Interconversion between a tree and a double-headed linked list
Problem Statement

A tree structure will be provided, it will either be in binary or unary format. The criteria are that after conversion when the list is traversed, the output should be the same sequence of elements as it will appear in the case of in-order traversal of the tree. The head of the list must match with the root of the tree, the preceding and succeeding elements must be the same in both cases. The last node should coincide with the ultimate leave node of the tree structure. Here is a diagrammatic representation of the above problem statement,

The above tree is in the binary format, it should be represented in the following format,


Explanation: There are various ways of proceeding with the solution to the given problem. The easiest way has been explained below.

The easiest way to proceed with the solution is to perform certain basic tree operations and then move ahead with the double-linked list operation. There are first of all three kinds of traversal options available to us, the first one that goes along the left-hand side called the pre-order, the next follows the right-hand side nodes, called the post order and the third but most important one is called the in-order traversal. This follows the central backbone of the nodes and displays the elements in a specific format. This method is going to be useful in our code. While performing the above traversal, the value of the previously visited node is stored and this continues to become a new node in the list. Once the pointer moves to the next element, this now becomes the successor of the previous element in the list. This way the list is formed.

Preparatory Last Minute Tips

The most important topics have been mentioned and the questions are always kept similar to the above-shown sets. There is no strict choice of language, students are free to choose whichever coding language they are comfortable with. The students may also have a subtle knowledge of graphs and backtracking if they want to, although those topics are not that important for coding rounds in any of the top-tier IT companies. Rest, prepare limited but prepare well.


With the hope that all doubts and queries have been answered, the last tip before ending the article will be to have the basic knowledge at the tip of the fingers. Be confident and do not panic. All the best!

Frequently Asked Questions

1. How many questions are asked in the written and the verbal coding rounds?

Ans – The number of questions in the written coding round is fixed to two, in all circumstances. However, the type and number of questions asked in the verbal rounds solely depend on the interviewer. This can start with two and go up to as many as 6 to 7 questions.

2. What are the selection criteria for Facebook?

Ans – Facebook has a quite flexible selection rate between 80-85%. The students are mostly judged in the first two rounds, and there is no disqualification rounds after that.

3. What should be the setup for an ideal interview situation?

Ans – The room should be lit and the camera should be able to detect the face. The candidate must be dressed in formal attire with a white shirt and dark-colored pants. The hair should be tied up and there should not be excessive makeup on the face. For the boys, they can choose to wear a tie but it must be of a single color.

Facebook Coding Interview Questions- Find More About It

Leave a Reply

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

Scroll to top