Facebook Interview Questions
- -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 - -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 - 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 - -1of 1 vote
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 - 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 - 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 - 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
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 - 0of 4 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 - 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 - -5of 5 votes
AnswersIf b == “1”:
- TubbyOPPO May 09, 2018 in England
quit()| Report Duplicate | Flag | PURGE
Facebook Software Engineer - 6of 6 votes
AnswersFB On-site March
- aonecoding April 21, 2018 in United States
Q: Find number of Islands.
XXXOO
OOOXX
XXOOX
Return 3 islands.
1 1 1OO
OOO2 2
3 3OO 2
Followup: If the board is too big to fit in memory, how to get the number?| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 1of 1 vote
AnswersGiven a string as input, return the list of all the patterns possible:
'1' : ['A', 'B', 'C'], '2' : ['D', 'E'], '12' : ['X'] '3' : ['P', 'Q']
Example if input is '123', then output should be [ADP, ADQ, AEP, AEQ, BDP, BDQ, BEP, BEQ, CDP, CDQ, CEP, CEQ, XP, XQ]
- ngupta32@hawk.iit.edu March 30, 2018 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm Coding Data Structures - 2of 2 votes
AnswersMarch 2018 Phone Interview FB
- aonecoding March 17, 2018 in United States
Calculate a moving average that considers the last N values.
Circular Queue (Interviewer didn't agree with the linked list queue that I suggested at first. Said the pointers took space)| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 0of 0 votes
AnswersGiven two input arrays, return true if the words array is sorted according to the ordering array
- releb February 28, 2018 in United States
Input:
words = ['cc', 'cb', 'bb', 'ac']
ordering = ['c', 'b', 'a']
Output: True
Input:
words = ['cc', 'cb', 'bb', 'ac']
ordering = ['b', 'c', 'a']
Output: False| Report Duplicate | Flag | PURGE
Facebook Software Engineer - 2of 2 votes
AnswersGive the following input, output if the array is sorted according to the ordering array given. Return true or false.
- releb February 28, 2018 in United States
Input:
words = ['cc', 'cb', 'bb', 'ac']
ordering = ['c', 'b', 'a']
Output: True
Input:
words = ['cc', 'cb', 'bb', 'ac']
[bb cb cc ac]
ordering = ['b', 'c', 'a']
Output: False| Report Duplicate | Flag | PURGE
Facebook Software Engineer - -1of 1 vote
AnswersDefine a class 'Space' which has a member string variable that indicates if the space is a "tree", a "house" or an empty space and another member variable that will store the 'space neighbors' (left, right, up and down only)
- d4niel February 27, 2018 in United States
Given a 'Grid' (list) of Spaces write the code for the findAll(start) method to find all the trees and houses given a 'Space' as start point
Example, Grid of 'Spaces':
T 0 0 H 0
0 0 0 0 0
H H T H 0
Where Ts are trees and Hs are houses| Report Duplicate | Flag | PURGE
Facebook Software Engineer Trees and Graphs - 0of 0 votes
AnswersImplement a trie tree which can add and search word, an extra "*" sign will also be considered, similar to Leetcode 211 but with "*"
- Aamir November 09, 2017 in United States
'*' means any sequence of characters (including the empty sequence).| Report Duplicate | Flag | PURGE
Facebook Software Engineer - 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 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 - 1of 1 vote
AnswersThe numbers on a telephone keypad are arranged thus:
1 2 3 4 5 6 7 8 9 0
Starting from any digit, and choosing successive digits as a knight moves in chess, determine how many different paths can be formed of length n. There is no need to make a list of the paths, only to count them.
- ajay.raj September 04, 2017 in United States
A knight moves two steps either horizontally or vertically followed by one step in the perpendicular direction; thus, from the digit 1 on the keypad a knight can move to digits 6 or 8, and from the digit 4 on the keypad a knight can move to digits 3, 9 or 0. A path may visit the same digit more than once.
Your task is to write a function that determines the number of paths of length n that a knight can trace on a keyboard starting from any digit .
public int findNumberOfPaths(int digit, int step){| Report Duplicate | Flag | PURGE
Facebook Software Engineer - 1of 1 vote
AnswersIf you are given 2 infinitely large integers in the form of strings, given the length of the string, find the product of the two integers.
- Anon August 15, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer - 0of 0 votes
AnswersHow will you multiply two infinitely large integers.
- Anon August 15, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer - 3of 3 votes
AnswersGiven a list of input tasks to run, and the cooldown interval, output the minimum number of time slots required to run them.
- nzt July 26, 2017 in United States
// Tasks: 1, 1, 2, 1, 2
// Recovery interval (cooldown): 2
// Output: 8 (order is 1 _ _ 1 2 _ 1 2 )
=========
Tasks are task numbers in that order coming in for execution. Cooling time is time interval required to cool down the machine after executing a task. So it's like if CPU executed task 1 then it needs 2 cooling time intervals before executing another task 1 but meanwhile, it can execute other tasks which are not same as 1 and so on. So before executing any task, you have to check if you have executed same task number before and if yes, then if its cooling time interval is done or not.
The output is basically the number of cycles/time slots CPU took to execute these tasks in that order (including when task executed and cooling intervals).| Report Duplicate | Flag | PURGE
Facebook Software Engineer - 0of 0 votes
Answersgiven a list of numbers, put with + - * / any two number, find the maximum value you can get.
- ajay.raj July 16, 2017 in United States
int getMaxNumber(int[] nums){
}| Report Duplicate | Flag | PURGE
Facebook Software Engineer