## Facebook Interview Questions

- 0of 0 votes

AnswersQuestion: Can you break the given string into words, provided by a given hashmap of frequency of word as <word: n>

- nitinguptaiit July 18, 2019 in United States

Example:

HashMap -> {"abc":3, "ab":2, "abca":1}

String: abcabcabcabca

output: Yes; [ abc, abc, abc , abca ]

Example:

HashMap -> {"abc":3, "ab":2}

String: abcabab

output: No

Example:

HashMap -> {"abc":3, "ab":2, "abca":1}

String: abcx

output: No| Report Duplicate | Flag | PURGE

Facebook Algorithm - 2of 2 votes

AnswersFind whether string S is periodic.

- acoding167 June 07, 2019 in United States

Periodic indicates S = nP.

e.g.

S = "ababab", then n = 3, and P = "ab"

S = "xxxxxx", then n = 1, and P = "x"

S = "aabbaaabba", then n = 2, and P = "aabba"

follow up:

Given string S, find out the P (repetitive pattern) of S.| Report Duplicate | Flag | PURGE

Facebook Software Engineer - 0of 0 votes

Answerswrite a JSON validator

- boony June 04, 2019 in United States| Report Duplicate | Flag | PURGE

Facebook Software Engineer Algorithm - 1of 1 vote

AnswersGiven an integer 'n', create an array such that each value is repeated twice. For example

- robb.krakow May 09, 2019 in United States

n = 3 --> [1,1,2,2,3,3]

n = 4 --> [1,1,2,2,3,3,4,4]

After creating it, find a permutation such that each number is spaced in such a way, they are at a "their value" distance from the second occurrence of the same number.

For example: n = 3 --> This is the array - [1,1,2,2,3,3]

Your output should be [3,1,2,1,3,2]

The second 3 is 3 digits away from the first 3.

The second 2 is 2 digits away from the first 2.

The second 1 is 1 digit away from the first 1.

Return any 1 permutation if it exists. Empty array if no permutation exists.

Follow up: Return all possible permutations.| Report Duplicate | Flag | PURGE

Facebook Software Engineer Data Structures - -4of 4 votes

Answers

- budfox April 25, 2019 in United States`;*************************************************************************** ; Imagine you have received a binary to reverse and you stumbled upon this ; function. What can you tell me about this function? Does anything stand ; out that makes you want to take a closer look? ; ; At a high level, explain what is going on. Then we will go into this code ; in more detail ;***************************************************************************`

| Report Duplicate | Flag | PURGE

Facebook Virus Researcher Assembly - 2of 2 votes

AnswersGenerate random max index

- acoding167 March 27, 2019 in United States

Given an array of integers, randomly return an index of the maximum value seen by far.

e.g.

Given [11,30,2,30,30,30,6,2,62, 62]

Having iterated up to the at element index 5 (where the last 30 is), randomly give an index among [1, 3, 4, 5] which are indices of 30 - the max value by far. Each index should have a ¼ chance to get picked.

Having iterated through the entire array, randomly give an index between 8 and 9 which are indices of the max value 62.| Report Duplicate | Flag | PURGE

Facebook Software Engineer - 0of 0 votes

AnswersLinkedList :

- ttemp3103 February 03, 2019 in United States

Input : A>B>C>D>E

Output: A>E>B>D>C| Report Duplicate | Flag | PURGE

Facebook - 0of 0 votes

AnswersGiven a

`struct drop{ float x_cordinate; float radius; }`

Return the number of calls that the function Drop() that returns a drop object, needs to be called so that the interval [0, 1) is covered. For each drop object the range covered are values on a line considering x_cordinate as center and radius as the length added on both sides of the x_cordinate on that line?

`int numCalls(const function<drop> Drop){ drop firstDrop = Drop(); // Code from here }`

For example, if the first Drop() call returns drop object drop.location as 0.5 (considering points on a 1d axis) and drop.radius as 0.2, then the interval covered is [0.3, 0.7). So how many calls need to be made to ensure the interval [0, 1) is covered. The location and radius can map to any real value.

- rahul January 21, 2019 in United States| Report Duplicate | Flag | PURGE

Facebook Software Engineer Intern - 2of 2 votes

AnswersGiven 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 - -1of 1 vote

AnswersComplicated problem statement but was asked to implement binary search

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

Facebook Intern - -1of 1 vote

AnswersSparse Scalar vector dot product.

- User042891 January 17, 2019 in United States

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

Facebook Intern - 2of 2 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 - 4of 4 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

AnswersHow 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

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

Open Chat in New Window