#### most common facebook coding interview questions

#### Below is a list of the 15 most frequently asked questions in a facebook interview

For detailed solutions to each question, you can visit

Grokking the Coding Interview: Patterns for Coding Questions

# 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.

#### find all paths for a sum

# 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

#### longest substring with no repeating characters

# Problem Statement

#

Given a string, find the length of the longest substring which has no repeating characters.

#### longest substring with at most 'k' distinct characters

# Problem Statement

#

Given a string, find the length of the longest substring in it with no more than K distinct characters.

# 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

#### alien dictionary

# 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.

#### find the ceiling of a number

# Problem Statement

#

Given an array of numbers sorted in an ascending order, find the ceiling of a given number ‘key’. The ceiling of the ‘key’ will be the smallest element in the given array greater than or equal to the ‘key’. Write a function to return the index of the ceiling of the ‘key’. If there isn’t any ceiling return -1.

For detailed solutions to each question, you can visit

Grokking the Coding Interview: Patterns for Coding Questions

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.