## Facebook Interview Questions

- 0of 0 votes

AnswersIn a tennis tournament of N players every player plays with every other player.

- geek2017 September 28, 2021 in United States

The following condition always hold-

If player P1 has won the match with P2 and player P2 has won from P3, then Player P1 has also defeated P3.

Find winner of tournament in O(N) time and O(1) space. Find rank of players in O(NlogN) time.| Report Duplicate | Flag | PURGE

Facebook Algorithm - 2of 2 votes

AnswersImplement binary addition of two strings.

- fruktoed August 14, 2020 in UK, London

For example "101101" and "111101" equal "1101010"

You cannot use any type conversion, operate only with strings.| Report Duplicate | Flag | PURGE

Facebook Android Engineer Algorithm - 0of 0 votes

Answersfind target in chess board with given start position of knight

- thosh July 31, 2020 in United States| Report Duplicate | Flag | PURGE

Facebook Software Engineer / Developer Algorithm - -4of 4 votes

AnswersGiven an integer array and an integer K, find the number of sub arrays in which all elements are less than K.

- neer.1304 June 01, 2020 in United States

Follow up -

Given an integer array and an integer K, find the number of non overlapping unordered pairs of sub arrays in which all elements are less than K.| Report Duplicate | Flag | PURGE

Facebook Software Engineer Algorithm - 5of 5 votes

AnswersGiven K sorted (ascending) arrays with N elements in each array, implement an iterator for iterating over the elements of the arrays in ascending order.

The constructor receives all of the input as array of arrays.

You need to implement the MyIterator class with a constructor and the following methods:`class MyIterator<T> { T next(); boolean hasNext(); }`

You are allowed to use only O(K) extra space with this class.

example:

input:`[[1,5,7], [2,3,10],[4,6,9]]`

The iterator should return:

- torchs January 13, 2020 in Israel`1,2,3,4,5,6,7,9,10`

| Report Duplicate | Flag | PURGE

Facebook Solutions Engineer Algorithm - 1of 1 vote

AnswerViews are not lifecycle aware that's true but what more? In modern development there is hardly any difference.

- kaustubh deshmukh December 01, 2019 in India| Report Duplicate | Flag | PURGE

Facebook Android Engineer Android - -1of 1 vote

Answersreverse an array for k distance.

- 786.senthil November 15, 2019 in United States

[2,3,1,5,4] and k =3

output : [2,3,1,5,4]

method

void reverse(int[] arr, k)

this method will only reverse the array

write another method which will sort the array by incorporating reverse method inside sort.

You must have to call reverse(arr,k) method to sort the array. You are not allowed to modify the reverse method| Report Duplicate | Flag | PURGE

Facebook Software Engineer - 1of 1 vote

AnswersGiven a length n, count the number of strings of length n that can be made using ‘a’, ‘b’ and ‘c’ with at-most one ‘b’ and two ‘c’s allowed.

- Nits September 07, 2019 in United States| Report Duplicate | Flag | PURGE

Facebook Software Development Manager Algorithm - 1of 3 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 - -6of 6 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 - 0of 2 votes

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

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

Open Chat in New Window