Oops!! It seems some javascript files did not load. Please hard reload(SHIFT + reload) your page.

Israel Tsadok

Sergey Kharagorgiev

What to expect at Facebook Interview?

**2 Telephonic interviews**which focus on basic problem solving and data structures**2-3 Coding Onsite interviews**which involve whiteboarding solutions to slightly harder data structures / algorithmic problems. The lesser experienced you are, the more number of coding onsite interview rounds for you.**0-1 System Design Onsite interviews**which involve coming up with high level design architectures for real life products. The more experienced you are, the more number of these interviews you might face.**1 Cultural Fit Onsite interview**which will evaluate whether you are a good cultural fit for Facebook depending on your attitude and previous work experience.

**Coding rounds :**Material in the programming section of InterviewBit is pretty comprehensive. For your reference, the section below has some of the questions which are frequently asked in Facebook's Interview. Make sure to try and solve most of them.**Design rounds :**InterviewBit System Design prep has you covered here. Make sure to go through some frequently asked interview problems listed on the page.**Cultural fit rounds :**In most cases, this should not be an issue. However, go through Cultural Fit Interview Guidelines to make sure you don't make common mistakes.

Solve Interview Problems asked at Facebook

Longest Increasing Subsequence

Find the **longest increasing subsequence** of a given sequence / array.

In other words, find a subsequence of array in which the subsequence’s elements are in strictly increasing order, and in which the subsequence is as long as possible.

This subsequence is not necessarily contiguous, or unique.

In this case, we only care about the **length** of the longest increasing subsequence.

**Example :**

```
Input : [0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15]
Output : 6
```

The sequence : `[0, 2, 6, 9, 13, 15]`

or `[0, 4, 6, 9, 11, 15]`

or `[0, 4, 6, 9, 13, 15]`

Solve Now

Unique Paths in a Grid

Given a grid of size m * n, lets assume you are starting at `(1,1)`

and your goal is to reach `(m,n)`

. At any instance, if you are on `(x,y)`

, you can either go to `(x, y + 1)`

or `(x + 1, y)`

.

Now consider if some obstacles are added to the grids. How many unique paths would there be?

An obstacle and empty space is marked as 1 and 0 respectively in the grid.

**Example :**

There is one obstacle in the middle of a 3x3 grid as illustrated below.

```
[
[0,0,0],
[0,1,0],
[0,0,0]
]
```

The total number of unique paths is `2`

.

Note:m and n will be at most 100.

Solve Now

Ways to Decode

A message containing letters from `A-Z `

is being encoded to numbers using the following mapping:

```
'A' -> 1
'B' -> 2
...
'Z' -> 26
```

Given an encoded message containing digits, determine the total number of ways to decode it.

**Example :**

Given encoded message `"12"`

, it could be decoded as `"AB"`

`(1 2)`

or `"L"`

`(12)`

.

The number of ways decoding `"12"`

is `2`

.

Solve Now

Best Time to Buy and Sell Stocks II

Say you have an array for which the ith element is the price of a given stock on day i.

Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).

**Example :**

```
Input : [1 2 3]
Return : 2
```

Solve Now

Best Time to Buy and Sell Stocks III

Say you have an array for which the ith element is the price of a given stock on day i.

Design an algorithm to find the maximum profit. You may complete at most two transactions.

Note:

You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).

**Example :**

```
Input : [1 2 1 2]
Output : 2
Explanation :
Day 1 : Buy
Day 2 : Sell
Day 3 : Buy
Day 4 : Sell
```

Solve Now

Best Time to Buy and Sell Stocks I

Say you have an array for which the ith element is the price of a given stock on day i.

If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.

**Example :**

```
Input : [1 2]
Return : 1
```

Solve Now

Regular Expression Match

Implement wildcard pattern matching with support for `'?'`

and `'*'`

.

`'?'`

: Matches any single character.`'*'`

: Matches any sequence of characters (including the empty sequence).

The matching should cover the entire input string (not partial).

The function prototype should be:

```
int isMatch(const char *s, const char *p)
```

**Examples :**

```
isMatch("aa","a") → 0
isMatch("aa","aa") → 1
isMatch("aaa","aa") → 0
isMatch("aa", "*") → 1
isMatch("aa", "a*") → 1
isMatch("ab", "?*") → 1
isMatch("aab", "c*a*b") → 0
```

Return 1/0 for this problem.

Solve Now

Regular Expression II

Implement regular expression matching with support for `'.'`

and `'*'`

.

`'.'`

Matches any single character.

`'*'`

Matches zero or more of the preceding element.

The matching should cover the entire input string (not partial).

The function prototype should be:

```
int isMatch(const char *s, const char *p)
```

Some examples:

```
isMatch("aa","a") → 0
isMatch("aa","aa") → 1
isMatch("aaa","aa") → 0
isMatch("aa", "a*") → 1
isMatch("aa", ".*") → 1
isMatch("ab", ".*") → 1
isMatch("aab", "c*a*b") → 1
```

Return `0 / 1`

( 0 for false, 1 for true ) for this problem

Solve Now

Add Two Numbers as Lists

You are given two linked lists representing two non-negative numbers. The digits are stored in **reverse order** and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.

Input: `(2 -> 4 -> 3)`

+ `(5 -> 6 -> 4)`

Output: `7 -> 0 -> 8`

```
342 + 465 = 807
```

Make sure there are no trailing zeros in the output list

So, `7 -> 0 -> 8 -> 0`

is not a valid response even though the value is still 807.

Solve Now

Reverse Link List II

Reverse a linked list from position m to n. Do it in-place and in one-pass.

For example:

Given `1->2->3->4->5->NULL`

, `m = 2`

and `n = 4`

,

return `1->4->3->2->5->NULL`

.

Note:

Given m, n satisfy the following condition:

`1 ≤ m ≤ n ≤ length of list`

.

Note 2:

Usually the version often seen in the interviews is reversing the whole linked list which is obviously an easier version of this question.

Solve Now