## Facebook Interview Questions

- 0of 0 votes

AnswerGiven a list of arrays of time intervals, write a function that calculates the total amount of time covered by the intervals.

- aonecoding4 January 19, 2019 in United States

For example:

input = [(1,4), (2,3)]

return 3

input = [(4,6), (1,2)]

return 3

input = {{1,4}, {6,8}, {2,4}, {7,9}, {10, 15}}

return 11| Report Duplicate | Flag | PURGE

Facebook Software Engineer - 0of 0 votes

AnswersYou are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.

- User042891 January 17, 2019 in United States| Report Duplicate | Flag | PURGE

Facebook Intern - 0of 0 votes

Answersgiven an array representing a non-negative integer (ex: 123 represented as [1,2,3]), return the next integer (output: [1,2,4]).

- User042891 January 17, 2019 in United States

run through all edge cases (ex: [9,9,9,9,9,9,9,9] etc)| Report Duplicate | Flag | PURGE

Facebook Intern - 0of 0 votes

AnswersComplicated problem statement but was asked to implement binary search

- User042891 January 17, 2019 in United States| Report Duplicate | Flag | PURGE

Facebook Intern - 0of 0 votes

AnswersSparse Scalar vector dot product.

- User042891 January 17, 2019 in United States

in less than O(n)| Report Duplicate | Flag | PURGE

Facebook Intern - 0of 0 votes

AnswersWrite a new data structure, "Dictionary with Last"

- Coder January 15, 2019 in United States

Methods:

set(key, value) - adds an element to the dictionary

get(key) - returns the element

delete(key) - removes the element

last() - returns the last key that was added or read.

In case a key was removed, last will return the previous key in order.| Report Duplicate | Flag | PURGE

Facebook Software Engineer Data Structures - 0of 0 votes

AnswersGiven an arbitrary tree remove nodes which have data value 0.

- keviIma December 31, 2018 in United States

As it stats arbitrary tree, I assumed n-ary tree.| Report Duplicate | Flag | PURGE

Facebook Software Engineer - 1of 1 vote

AnswersConvert a binary tree to a doubly linked circular linked list.(Tree is binary and not BST).Hint: using Inorder Traversal

- aifra2000 December 17, 2018 in United States for Multiple| Report Duplicate | Flag | PURGE

Facebook Software Engineer - 3of 3 votes

AnswersGiven many coins of 3 different face values, print the combination sums of the coins up to 1000. Must be printed in order.

- aonecoding4 December 16, 2018 in United States

eg: coins(10, 15, 55)

print:

10

15

20

25

30

.

.

.

1000| Report Duplicate | Flag | PURGE

Facebook Software Engineer - 1of 1 vote

Answersl1=[1,2,3,4]

- nikhil19kekan December 04, 2018 in United States for Community Operations

l2=[1,3,6,7,null,null,null,null]

output: l2=[1,1,2,3,3,4,6,7]| Report Duplicate | Flag | PURGE

Facebook Software Developer - 1of 1 vote

Answersk=2, l=[1,2,3,4,5,6]

- nikhil19kekan December 04, 2018 in United States for Community Operations

output: l=[5,6,1,2,3,4]

In place O(1) space complexity| Report Duplicate | Flag | PURGE

Facebook Software Developer Arrays - 1of 1 vote

AnswersAdd two numbers represented as LinkedList (not LeetCode 445 which uses ListNode)

- KelvinLong8897 November 17, 2018 in United States

e.g

inputs: '5'->'6'->'3'

'8'->'4'->'2'

output: '1'->'4'->'0'->'5'

method signature:

LinkedList<Integer> sumList(LinkedList<Integer> l1, LinkedList<Integer> l2)| Report Duplicate | Flag | PURGE

Facebook Android Engineer Algorithm - 1of 1 vote

AnswersYou have two sorted arrays, where each element is an interval. Now, merge the two array, overlapping intervals can be merged as a single one.

- Seetha November 11, 2018 in United States

I/P :

List 1 [1,2] , [3,9]

List 2 [4,5], [8, 10], [11,12]

O/P [1,2], [3,10], [11,12]| Report Duplicate | Flag | PURGE

Facebook Software Developer - 0of 0 votes

AnswersI/P [8, 3, 2, [5, 6, [9]], 6]

- Seetha November 11, 2018 in United States

O/P 8+3+2+2*(5+6+3*(9))+6 => 95| Report Duplicate | Flag | PURGE

Facebook Software Developer Arrays - 1of 1 vote

Answersfind all numbers the sum of cube of each digits is the number itself

- Aamir November 09, 2018 in United States

ex:153=1^3+5^3+3^3| Report Duplicate | Flag | PURGE

Facebook Software Engineer Intern - 0of 0 votes

AnswersYou are given an array A of size N and Q queries. For each query, you are given two indices of the array L and R. The subarray generated from L to R is reversed. Your task is to determine the maximum sum of the subarrays.

- Sameer October 29, 2018 in United States

Note: After each query is solved, the array comes to its initial states.

Input format

First line: Two space-separated integers N and Q

Next line: N space-separated integers denoting the array elements.

Next

Q lines: Two space-separated integers in every line denoting the values of Li and Ri

Output format

For each query, print the required answer in a new line.

5 2

3 -1 4 2 -1

3 4

1 2

//output

8

9| Report Duplicate | Flag | PURGE

Facebook Software Developer - 0of 0 votes

AnswersConvert infix to postfix and evaluate postfix expression.

- user October 28, 2018 in United States

For example: 4 // number of variables

g = 2

p = 3

t = 1

w = 2

3 // number of equations

g + p x t - w x p

t - g + t - w

e + t x t - m

Output: -1 //for first equation

-2 //for second equation

Compilation Error // for third equation| Report Duplicate | Flag | PURGE

Facebook Testing / Quality Assurance - 0of 0 votes

AnswersConvert infix to postfix and evaluate postfix expression.

- user October 28, 2018 in United States

For example: Input:

3 // number of variables

a = 1

b = 2

c = 2

2 // number of equations

a x b + a x c + b x c

a x c - b / c + c x c

Output: 8 //for first equation

5 // for second equation| Report Duplicate | Flag | PURGE

Facebook Testing / Quality Assurance - 1of 1 vote

AnswerHow to evaluate a mathematical expression by compiler design. The program will ask the user to input a value (say n). Then user will input n lines of input each of which contains an identifier and its corresponding value. Then program will ask the user again to input a value (say m). Then user will input m lines of expressions. Calculate the final value for each of the given expression using first n lines of input. If you can't evaluate any expression from given numbers of identifiers then output 'Compilation Error'. Allowed mathematical operators are +(add), -(subtract), x(multiply), /(divide).

- user October 27, 2018 in United States

Example: a = 1

b = 2

c = 2

a x b + a x c + b x c output 8

a x c - b / c + c x c out put 5

g = 2

p = 3

t = 1

w = 2

g + p x t - w x p output -1

t - g + t - w output -2

e + t x t - m output compilation error| Report Duplicate | Flag | PURGE

Facebook Software Engineer - 2of 2 votes

AnswersGiven the root of a binary tree, print the nodes column wise and row wise.

`..............6 ............/....\ ...........9......4 ........../..\......\ .........5....1.....3 ..........\........./ ...........0.......7`

The answer would be 5 9 0 6 1 4 7 3.

- Champaklal October 26, 2018 in United States| Report Duplicate | Flag | PURGE

Facebook Software Developer Algorithm - 1of 1 vote

AnswersGiven a list of Contacts, where each contact consists of a contact ID and a list of email IDs. Output a unique list of contacts by removing duplicates. Two contacts are considered to be the same, if they share at least one email ID.

- MM2181 August 19, 2018 in United States| Report Duplicate | Flag | PURGE

Facebook Web Developer - 2of 2 votes

AnswersGiven an integer, print an English phrase that describes the integer (eg, "Two hundred and thirty four", “One Thousand, Two Hundred and Thirty Four”)

- MM2181 August 19, 2018 in United States| Report Duplicate | Flag | PURGE

Facebook Web Developer - 1of 1 vote

AnswersYou are given n points (x1, y1), (x2, y2), ..... (xm, ym) of a two dimensional graph. Find 'n' closest points to (0,0) [ n <= m ]. Euclidean distance can be used to find the distance between 2 points.

- MM2181 August 19, 2018 in United States| Report Duplicate | Flag | PURGE

Facebook Web Developer - 0of 0 votes

Answerswrite a class that 1) calculates the average of the stream, 2) provides an API read the average.

- samayragoyal990 August 10, 2018 in United States

Handle overflows as the numbers can be very large and not fit into double/long.| Report Duplicate | Flag | PURGE

Facebook SDE-3 Coding - -1of 3 votes

AnswersGiven an array of lower case strings, the task is to find the number of strings that are special equivalent.

- boony August 09, 2018 in United States

Two strings are special equivalent if they can be made equivalent by performing some operations on one or both string

swapEven : swap a character at an even-numbered index with a character at another even-numbered index

swapOdd : swap a character at an odd-numbered index with a character at another odd-numbered index

Input : arr = {"abcd", "cbad", "bacd"}

Output : 2

The 2nd string can be converted to the 1st by swapping

the first and third characters. So there are 2 distinct

strings as the third string cannot be converted to the

first.

string input[] = {"abcd", "acbd", "adcb", "cdba",

"bcda", "badc"};

ans =4| Report Duplicate | Flag | PURGE

Facebook Software Engineer - 2of 2 votes

AnswersGiven 2 strings representing very large numbers (these are not representable as a BigInteger or other various type) write a method for adding the two numbers and returning their sum.

- Scott.T.Rogers July 06, 2018 in United States| Report Duplicate | Flag | PURGE

Facebook Senior Software Development Engineer Algorithm - -3of 5 votes

Answerword look up

- bryan July 06, 2018 in United States| Report Duplicate | Flag | PURGE

Facebook Data Structures - 2of 2 votes

AnswersI was asked to design a system on a whiteboard which simulate a executor.

- Patrick July 01, 2018 in United States

This system has a method that is being triggered every second. I need to add logic to the method (i.e. run jobs).

There is also a method called job_arrived() that is called when a new job arrives.. I need to implement it as well.

I needed to implement a system which tries to run each job right when it is arrived (it has a return value that gets a success status from a black box service). if the job ran successfully that's the end of it..

if not I need to re-run it after 2 seconds (and if that fails as well - there will be no re-runs).

of course - more than one job can be accepted each second.

I was asked to describes the system (describe the classes and method) and consider the system to be large scale one (meaning.. threading is in order here..).

The answer I gave was apparently not multi threaded enough..

any idea to what I should have done?

Thanks guys| Report Duplicate | Flag | PURGE

Facebook Software Developer Java - 5of 5 votes

AnswersCongrats on aonecode member A.P. for signing the offer with FB! Thanks for sharing the experience with us.

- aonecoding May 24, 2018 in United States

phone:

postorder tree traversal recursive -> iterative

add two binary number

on-site:

1 ring buffer

2 merge intervals

3 Leetcode alien dictionary

4.sort list of words| Report Duplicate | Flag | PURGE

Facebook Software Engineer Algorithm - 1of 1 vote

AnswersGiven a number, rearrange the digits of that number to make a higher number, among all such permutations that are greater,one of them is the smallest, Find the smallest greater permutation (the next Permutation).

- sarunreddy82 May 13, 2018 in United States

Examples:

next_permutation (12) = 21

next_permutation (315) = 351

next_permutation (583) = 835

next_permutation (12389) = 12398

next_permutation (34722641) = 34724126| Report Duplicate | Flag | PURGE

Facebook Java

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

Open Chat in New Window