# most common facebook coding interview questions

## the 15 most asked questions in a facebook coding interview

### Arrays

Move zeros to the left

#### â€‹

Problem statement

â€‹

Given an integer array, move all elements that are equal to 0 to the left while maintaining the order of other elements in the array.

â€‹

Merge overlapping intervals

#### â€‹

Problem statement

â€‹

Given a list of intervals, merge all the overlapping intervals to produce a list that has only mutually exclusive intervals.

â€‹

### linked lists

Add two integers

#### â€‹

Problem statement

â€‹

Given the head pointers of two linked lists where each linked list represents an integer number (each node is a digit), add them and return the resulting linked list.

â€‹

Merge two sorted linked lists

#### â€‹

Problem statement

â€‹

Given two sorted linked lists, merge them so that the resulting linked list is also sorted.

â€‹

### trees

Convert binary tree to doubly linked list

#### â€‹

Problem statement

â€‹

Convert a binary tree to a doubly linked list so that the order of the doubly linked list is the same as an in-order traversal of the binary tree. After conversion, the left pointer of the node should be pointing to the previous node in the doubly linked list, and the right pointer should be pointing to the next node in the doubly linked list.

â€‹

Level order traversal of binary tree

#### â€‹

Problem statement

â€‹

Given a binary tree and a number ‘S’, find all paths from root-to-leaf such that the sum of all the node values of each path equals ‘S’.

â€‹

### strings

Reverse words in a sentence

#### â€‹

Problem statement

â€‹

Reverse the order of words in a given sentence (an array of characters).

â€‹

String segmentation

#### â€‹

Problem statement

â€‹

Given a dictionary of words and an input string tell whether the input string can be completely segmented into dictionary words.

â€‹

### dynamic programming

Find maximum single sell profit

#### â€‹

Problem statement

â€‹

Given a list of daily stock prices (integers for simplicity), return the buy and sell prices for making the maximum profit. We need to maximize the single buy/sell profit. If we can't make any profit, we'll try to minimize the loss.

â€‹

### Math and stats

Calculate the power of a number

#### â€‹

Problem statement

â€‹

Given a double, 'x', and an integer, 'n', write a function to calculate 'x' raised to the power 'n'.

â€‹

### backtracking

Find all possible subsets

#### â€‹

Problem statement

â€‹

You are given a set of integers and you have to find all the possible subsets of this set of integers.

â€‹

### Graphs

Clone a directed graph

#### â€‹

Problem statement

â€‹

â€‹

### design

Serialize / deserialize binary tree

#### â€‹

Problem statement

â€‹

Serialize a binary tree to a file and then deserialize it back to a tree so that the original and the deserialized trees are identical.

â€‹

### sorting and searching

Find the high and low index

#### â€‹

Problem statement

â€‹

Given a sorted array of integers, return the low and high index of the given key. Return -1 if not found. The array length can be in the millions with many duplicates.

â€‹

Search rotated array

#### â€‹

Problem statement

â€‹

Search for a given number in a sorted array that has been rotated by some arbitrary number.

â€‹

have you been asked a question that is not included here in your facebook interview?

â€‹

please share with us:

Need help preparing for the interview?

â€‹

Check out the Definitive Interview Prep Roadmap,

written and reviewed by real hiring managers.