## Facebook Interview Questions

- 0of 0 votes
"""

Given a 2d array of 0s and 1s, 0 means water,

1 means land, connected 1s form an island,

count the number of islands on this map.

01010

01001

01101

returns 3

"""

- 0of 0 votes
# Given a dictionary, find all pairs of words that,

# when concatenated together, form a palindrome.

# ‘none', 'xenon': 'nonexenon' is a palindrome

# 'none', 'xexenon': 'nonexexenon' is a palindrome

- 0of 0 votes
How would you work with a backend engineer to design a news feed on mobile. Imagine that we only care about showing the user feed and posting a picture.

Follow-ups

1. what kind of apis would you want him to expose and what would they look like

2. How would you refresh the news feed on the iOS app and how often?

3. How would you cache the data/images. What size cache would you have?

- 0of 0 votes
Given an aray with ['a1', 'a2', .....'aN', 'b1', 'b2', ....'bN', 'c1', 'c2', .....'cN'],

stagger the subarrays so it becomes ['a1', 'b1', 'c1', 'a2', 'b2', 'c2', ...'aN', 'bN', 'cN']. The optimal solution requires linear-time

sorting and a constant space complexity.

- 0of 0 votes
How to design a spreadsheet program? How do you know to update a field after another

field was changed that it depended on?

- 0of 0 votes
Given a set of points in the 2D coordinate system, find the radius of the

smallest circle which encompasses

all the given points

- 0of 0 votes
Try to come up with a combination of two data structures to implement a

data structure that supports search,

delete in O(1) time and insert in O(n) time.Try to come up with a combination of two data structures to implement a

data structure that supports search,

delete in O(1) time and insert in O(n) time.

- 0of 0 votes
Write a program to print all the columns of a binary tree from left to right and top down.

- 0of 0 votes
Given list of strings like “ crane, drain, refrain” and a pattern such as *an*

where * can match any number of chracters.

Return the matching word in an efficient manner.

Answer to above question : crane

- 0of 0 votes
Given a MxN matrix where each element can either be 0 or 1. We need to print the shortest path between a given source cell to a destination cell. The path can only be created out of a cell if its value is 1.

BFS is trival, please solve it use DFS

public void print(int[][] matrix, int[] start, int[] end){

}

- -3of 3 votes
Warning! User majia168 is posting fake interview questions!

- 0of 0 votes
Given a non-empty string s, you may delete at most k characters. Judge whether you can make it a palindrome.

- 0of 0 votes
Given a list of input tasks to run, and the cooldown interval, output the minimum number of time slots required to run them.

// Tasks: 1, 1, 2, 1, 2

// Recovery interval (cooldown): 2

// Output: 8 (order is 1 _ _ 1 2 _ 1 2 )

Whats the time and space complexity ? What's the ideal case of space complexity ?

- 0of 0 votes
Find the maximum sum of subset of size K in an array

- 0of 0 votes
Given an array (may have negative num) and an integer(may be negative), find the smallest subarray whose sum is >= the given integer.

int[] nums2 = {5,4,-8,16};

int x=10;

return 1, because 16 >= x

try to solve it in o(n) time

public static int miniSubArrayLen(int[] nums, int s) {

- 0of 0 votes
Given a List determine if contiguous elements of the List sum to an input number. For example: Array/List [6 5 3 2 1 7], and input number 8. The numbers 5 + 3 = 8. Or suppose an input number 10, the elements of the list 2 + 1 + 7 = 10.

- 0of 0 votes
find LCA in directed acyclic graph

class Node {

int label;

List<Node> neighbors;

Node(int x) {

label = x;

neighbors = new ArrayList<>();

}

}

public List<Node> findLCAINDAG(Node, graph, Node n1, Node n2)

- 0of 0 votes
Say you have an array for which the ith element is the price of a given stock on day i, you can buy stock at any day, but can only buy once a day, but if you sell the stock, you must sell all of them at once.

Seeking maximum profit

public int maxProfit(int[] prices) {

- 0of 0 votes
Given a binary tree, print the path that has the maximum path sum.

For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The path must contain at least one node and does not need to go through the root. the node val may be negative one`For example: Given the below binary tree, 1 / \ 2 3 Return 2-1-3. -1 / \ -2 3 \ -1 Return 3. public List<Integer> findMaxPath(TreeNode root){ } /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */`

- 0of 0 votes
find the longest substring with at most k repeating characters,

to make it more clear, at most k repeating characters means in the substring, the max count(frequency) of one or more chars is k

- 0of 0 votes
Robot walked from the upper left to the lower right, can only go down and to the right, the number of each grid is height,

If the next cell height is higher than the current, we must pay the difference cost, otherwise no cost,

Find the minimum cost to reach the lower right corner,

Follow up 1, print the minimum cost path;

- 0of 0 votes
Expression evolution

expr :: = int | '(' op expr + ')'

op :: = '+' | '*'

Cite a few examples:

"3" -> 3

"(+ 1 2)" -> 3

"(+ 3 4 5)" -> 12

"(+7 (* 8 12) (* 2 (+ 9 4) 7) 3)" -> ...

Public int getValue(String s){

}

- 0of 0 votes
`Insert a number into an array of sorted intervals. For example, [1,4], [6,8], after insert 5, return [1,8]. class Interval{ int start; int end; public Interval(int start, int end){ this.start = start; this.end = end; } } class Solution{ public List<Interval> insert(List<Interval> list, int val){ } }`

- 0of 0 votes
determine whether a number is the sum of two squares, such as 17 = 16 +1

- 0of 0 votes
`Give a matrix, for example 1 0 0 1 0 0 0 1 0 1 0 0 0 1 0 1 0 1 0 1 Find if there is a rectangle in the matrix, all four corners are 1 For the example, there is only one rectangle, that is 1 0 1 0 1 0 1 0 1`

- 0of 0 votes
class DirectedGraphNode {

int label;

List<DirectedGraphNode> neighbors;

DirectedGraphNode(int x) {

label = x;

neighbors = new ArrayList<>();

}

}

check if there is a cycle in a directed graph, if there is a cycle, remove all the cycles

- 0of 0 votes
given a string and a segmentation length k

For example:

"This is a good day" k = 10

Cut into:

"This (1/4)"

"is a (2/4)"

"good (3/4)"

"day (4/4)"

Each line followed by a suffix in the form of (i/n) has 10 chars including space (except for the last line), return the minimum cut required, for the example, just return 4.

- 0of 0 votes
trie search, Search Return all words that match the wildcard *

such as

add ("car")

add ("caw")

add ("cauw")

search ("c*w") returns "caw" and "cauw".

- 0of 0 votes
given a target node in a directed graph, find the shortest cycle including this node, return the whole path.

- 0of 0 votes
Implement a trie tree which can add and search word, an extra "*" sign will also be considered, similar to Leetcode 211 but with "*"

'*' means any sequence of characters (including the empty sequence).