## Facebook Interview Questions

- 0of 0 votes

AnswersExplain in detail about your favourite android api.

- me.samyakjain November 03, 2017 in United States| Report Duplicate | Flag | PURGE

Facebook Android Engineer Android - 0of 0 votes

Answersgiven 2 list of interval representing users online offline timestamp e.g (already sorted), find all intervals that both of users are online.

- ajay.raj November 03, 2017 in United States

e.g A= [(3, 5), (7, 11)] B=[(2, 4), (9, 10)] --> [(3, 4), (9, 10)].| Report Duplicate | Flag | PURGE

Facebook SDE1 - 2of 2 votes

AnswerFacebook

- aonecoding November 03, 2017 in United States

-Phone: LC304 & longest arithmetic sequence. Return the sequence.| Report Duplicate | Flag | PURGE

Facebook Software Engineer Algorithm - 0of 0 votes

AnswersGiven an array of integers and k, find the difference between the number of the strictly increasing number of subarrays (of size more than one) and the number of the strictly decreasing subarray in the window of size k. your method should be time and space efficent

- ajay.raj November 03, 2017 in United States

example

int[] nums = {188930, 194123, 201345, 154243, 154243};

int k = 3;

Output

3, 0, -1

Explanation

For the first window of [188930, 194123, 201345], there are 3 increasing subranges ([188930, 194123, 201345], [188930, 194123], and [194123, 201345]) and 0 decreasing, so the answer is 3. For the second window of [194123, 201345, 154243], there is 1 increasing subrange and 1 decreasing, so the answer is 0. For the third window of [201345, 154243, 154243], there is 1 decreasing subrange and 0 increasing, so the answer is -1.

public int[] getdiff(int[] nums, int l){

}| Report Duplicate | Flag | PURGE

Facebook SDE1 - 0of 0 votes

Answers

- ajay.raj October 31, 2017 in United States`There is an unordered interval stream, write a method, returns the total length that all intervals cover by now class Interval{ int start; int end; } public List<Integer> countCoverLength(Iterator<Interval> stream){ }`

| Report Duplicate | Flag | PURGE

Facebook SDE1 - 0of 0 votes

Answers‘.’Matches any single character,' * 'Matches any sequence of characters (including the empty sequence).

- ajay.raj October 28, 2017 in United States

There are two input, one is string pattern, and the other is dictionary like dict = ["cat", "cats", "and", "sand", "dog"].

return a boolean: whether to find a dictionary in the pattern match the word

eg: dict = ["cat", "cats", "and", "sand", "dog"].

pattern = "* t", -> true (can match cat)

pattern = ".a *" -> true (can match cat, cats, can also match sand, because * can also express empty sequence)| Report Duplicate | Flag | PURGE

Facebook SDE1 - 0of 0 votes

AnswersHow would you store and retrieve values in Memcache if the values are larger than the individual value size allowed by Memcache?

- ajay.raj October 25, 2017 in United States| Report Duplicate | Flag | PURGE

Facebook SDE1 - 2of 2 votes

Answersnode {

- ajay.raj October 23, 2017 in United States

node * left, * right;

}

Given a list of node to determine whether the node in the list can form a valid binary tree. several points of judgment

1. need to ensure that all left, right pointer point to the node inside list

2. no cycle

3. All node must be connected

Boolean isValidTree(List<Node> list){}| Report Duplicate | Flag | PURGE

Facebook Software Developer - 1of 1 vote

AnswersGiven a matrix of N * M, given the coordinates (x, y) present in a matrix,

- ajay.raj October 23, 2017 in United States

Find the number of paths that can reach (0, 0) from the (x, y) points with k steps (requires exactly k, k> = 0)

From each point you can go up, down, left and right in four directions.

For example, the following matrix:

----------

0 0 0 0 0

0 0 0 0 0

0 0 0 0 0

0 0 0 0 0

(x, y) = (1, 1), k = 2, the output is 2| Report Duplicate | Flag | PURGE

Facebook Software Developer - 0of 0 votes

AnswersFind all words [A-Z] in a dictionary (about 1M words) that are made of a subset (in any order) of the chars in the input parameter [A-Z].

- ajay.raj October 19, 2017 in United States

ex: input "ACRAT" (10 to 20 chars, up to 30 worst case)

matching words: "A", "CAR", "ACA", "ART", "RAC".

non-matching words: "BAR", "AAA"

follow up : the input is a list of words. Return a list of words that each

list is formed by exactly the characters in the input list.

For example: two lists {“DEBIT”, “CARD”} and{“BAD”, “CREDIT”}

are formed by the same exact group of characters.| Report Duplicate | Flag | PURGE

Facebook SDE1 - 0of 0 votes

AnswersGiven a sorted list of integers, square the elements and give the output in sorted order.

- nra October 19, 2017 in United States| Report Duplicate | Flag | PURGE

Facebook Software Engineer - 0of 0 votes

AnswersFind the distance between the farthest two elements in a binary tree.

- nra October 19, 2017 in United States| Report Duplicate | Flag | PURGE

Facebook Software Engineer Algorithm - 0of 0 votes

AnswersGiven a string separated by a space like "123456 abc+efg" determine

- ajay.raj October 18, 2017 in United States

the solution by mapping integers to letters like a:1, b:2, c:3, d:4, e:5, f:6.

The only operations allowed were + or -. So the calculated solution

that made the tests pass was 123+456 = 579.| Report Duplicate | Flag | PURGE

Facebook SDE1 - 0of 0 votes

AnswersHow many subsets of a given array sum to zero?

- ajay.raj October 18, 2017 in United States| Report Duplicate | Flag | PURGE

Facebook SDE1 - 0of 0 votes

AnswersGiven numbers 1 through 52, take 5 unique numbers and determine

- ajay.raj October 18, 2017 in United States

if the number 42 can be made using any combination of addition (+),

subtraction (-), multiplication (*), and division (/) on those 5 numbers| Report Duplicate | Flag | PURGE

Facebook SDE1 - 1of 1 vote

Answers/* Intersection of two sorted interval lists, A=[(1,2), (5,7)..]

B=[(2,6)...] return [(5,6)..] */

- ajay.raj October 09, 2017 in United States`import java.util.*; class Interval{ int start; int end; public Interval(int start, int end){ this.start = start; this.end = end; } } class Solution { public List<Interval> Intersection(Interval[] i1, Interval[] i2) {}`

| Report Duplicate | Flag | PURGE

Facebook SDE1 - 0of 0 votes

Answers* Given a string on length N. You can swap only the adjacent elements

- ajay.raj October 02, 2017 in United States

and each element can be swapped atmost once.

Find the no of permutations of the string that can be generated after

performing the swaps as mentioned.

Ex –

string – “12345”

Ans = 8

Explanations- (All the permutations)

12345

21345

13245

12435

12354

21435

13254

21354| Report Duplicate | Flag | PURGE

Facebook SDE1 - 0of 0 votes

AnswersGiven an array of n positive integers, find the number of subarrays

- ajay.raj October 02, 2017 in United States

such that product of the elements of those subarrays are less than k.

For eg. Arr= {2, 3, 6} k=10

No of such subarrays= 4| Report Duplicate | Flag | PURGE

Facebook SDE1 - 1of 1 vote

AnswersPrint the levels of a binary tree in reverse order using stack and recursion

`Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). For example: Given binary tree 3 / \ 9 20 / \ 15 7 return its bottom-up level order traversal as: [ [15,7], [9,20], [3] ]`

public List<List<Integer>> levelOrderBottom(TreeNode root) {

- ajay.raj October 02, 2017 in United States

}| Report Duplicate | Flag | PURGE

Facebook SDE1 - 0of 0 votes

Answersgiven an array, find whether there exists 3 elements a,b,c in it such that a+b=c using efficient method.

- ajay.raj October 02, 2017 in United States| Report Duplicate | Flag | PURGE

Facebook SDE1 - 0of 0 votes

AnswersYou are provided a BST, which is corrupted. One of the nodes in it has 2 parents.

- ajay.raj October 02, 2017 in United States

Let’s say those are parent 1 and parent 2. It is ensured that none

of these parents will be the ancestor of the other. Identify the node,

and remove the link of the wrong parent.| Report Duplicate | Flag | PURGE

Facebook SDE1 - 1of 1 vote

Answersgiven an array of strings and characters, make the largest string possible.

- ajay.raj October 02, 2017 in United States

The resultant string should be a combination of the strings given in the array.

The given array

of characters may contain repeated elements.

Example – Given char array – {a,a,b,c,d,d,e,c} and given strings

– {abba, aabc, de, cde} the

ans is aabccde| Report Duplicate | Flag | PURGE

Facebook SDET - 1of 1 vote

AnswersGiven an adjacency matrix of a directed graph, find the number of cycles in the graph

- ajay.raj October 02, 2017 in United States| Report Duplicate | Flag | PURGE

Facebook SDE1 - 0of 0 votes

AnswersGiven K sorted (ascending) arrays. Write an iterator class that iterate over the arrays and returns the next element. Duplicate are allowed. What is the complexity to iterate the entire arrays? what is the complexity for each iteration?

Example:`arr1 = {1,2,3,4,7,9} arr2 = {3,5,6,8,10}`

The iterator should return:

`1,2,3,3,4,5,6,7,8,9,10`

Extension:

Don't return duplicates, so the above iterator should return:

- PenChief September 29, 2017 in Israel`1,2,3,4,5,6,7,8,9,10`

| Report Duplicate | Flag | PURGE

Facebook - 1of 1 vote

AnswersGiven a binary tree that complies to the following rule:

The parent node value is always the the result of the AND operator of its children values.

You modify one of the LEAF nodes value (e.g. if it was 1 it is now 0). Write a function that fixes the tree

so it complies with the above rule.

- PenChief September 19, 2017 in Israel`// // 0 1 // / \ / \ // 1 0 =====> 1 1 // / \ / \ / \ / \ // 1 1 0 1 1 1 1 1 // // The parent node value is always children value's LOGICAL AND // & //`

| Report Duplicate | Flag | PURGE

Facebook Algorithm - 0of 0 votes

AnswersGiven an array of integers, return the index of the max value in this array.

Note:

If the max value appears more than once, the function should return one the indexes, but make it so that the next call will return different index.

Important: you are not allowed to store state between calls

Example: given this input array`// 0 -1 6 4 5 6 6 // | | | // 2,1/3 5,1/3 6,1/3`

Function signature:

`int getIndex(const std::vector<int>& numbers);`

Example output:

`2 5 6 5 2`

Extension:

What if you knew how many times the max value appears in the array, can you improve the function performance?

So using the given example array, the function signature is now:

- PenChief September 19, 2017 in Israel`int getIndex(const std::vector<int>& numbers, int maxCount);`

| Report Duplicate | Flag | PURGE

Facebook Algorithm - 0of 0 votes

Answers

- ajay.raj September 19, 2017 in United States`Given an array of n * m matrix, and a moving matrix window (size k * k), move the window from top left to bottom right at each iteration, find the median number inside the window at each moving Can you do it better than brutal force method? void getMedian(int[][] matrix, int k){ print median } For matrix [ [1, 5, 3], [3, 2, 1], [4, 1, 9], ] The moving window size k = 2. At first the window is at the start of the array like this [ [|1, 5|, 3], [|3, 2|, 1], [4, 1, 9], ] ,get the median (2 + 3) / 2 = 2.5; then the window move one step forward. [ [1, |5, 3|], [3, |2, 1|], [4, 1, 9], ] ,get the median (2 + 3) / 2 = 2.5 then the window move one step forward again. [ [1, 5, 3], [|3, 2|, 1], [|4, 1|, 9], ] ,get the median (2 + 3) / 2 = 2.5 then the window move one step forward again. [ [1, 5, 3], [3, |2, 1|], [4, |1, 9|], ] ,get the median (1 + 2) / 2 = 1.5`

| Report Duplicate | Flag | PURGE

Facebook SDE1 - 3of 3 votes

AnswersWe are planning an orienteering game.

- ajay.raj September 19, 2017 in United States

The aim of this game is to arrive at the goal (G) from the start (S) with the shortest distance.

However, the players have to pass all the checkpoints (@) on the map.

An orienteering map is to be given in the following format.

########

#@....G#

##.##@##

#..@..S#

#@.....#

########

In this problem, an orienteering map is to be given.

Calculate the minimum distance from the start to the goal with passing all the checkpoints.

Specification

* A map consists of 5 characters as following.

You can assume that the map does not contain any invalid characters and

the map has exactly one start symbol 'S' and exactly one goal symbol 'G'.

* 'S' means the orienteering start.

* 'G' means the orienteering goal.

* '@' means an orienteering checkpoint.

* '.' means an opened-block that players can pass.

* '#' means a closed-block that players cannot pass.

* It is allowed to move only by one step vertically or horizontally (up, down, left, or right) to the

next block.

Other types of movements, such as moving diagonally (left up, right up, left down and right down)

and skipping one or more blocks, are NOT permitted.

* You MUST NOT get out of the map.

* Distance is to be defined as the number of movements to the different blocks.

* You CAN pass opened-blocks, checkpoints, the start, and the goal more than once if necessary.

* You can assume that parameters satisfy following conditions.

* 1 <= width <= 100

* 1 <= height <= 100

* The maximum number of checkpoints is 18.| Report Duplicate | Flag | PURGE

Facebook SDE1 - 0of 0 votes

Answersconvert prefix to postfix expression

- ajay.raj September 16, 2017 in United States

public String convert2postfix(String prefix){

}| Report Duplicate | Flag | PURGE

Facebook SDE1 - 1of 1 vote

AnswersGiven an array of integers where each element points to the index of the next element how would you detect if there is a cycle in this array

- ajay.raj September 12, 2017 in United States

can you do it without extra space| Report Duplicate | Flag | PURGE

Facebook SDE1

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window