Facebook Interview Questions
- 0of 0 votes
AnswersPrint a binary tree in level order with a new line after every level.
- April 15, 2011| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer - 1of 1 vote
AnswersWrite a c++ program to find the LCM of all the elements of an array.
- crackit March 03, 2011| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 1of 1 vote
AnswersYou are given N ranges of date offsets when N employees are present in an organization. Something like
- abc March 01, 2011
1-4 (i.e. employee will come on 1st, 2nd, 3rd and 4th day )
2-6
8-9
..
1-14
You have to organize an event on minimum number of days such that each employee can attend the event at least twice. Write an algorithm (there is apparently an O(n) algorithm for this).| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer - 3of 3 votes
AnswersFirst the interviewer have called me on time, he introduced himself and his project which takes about 10 minutes, then he asked me why do you want to join facebook..
- neal January 05, 2011
Then he started in the technical questions, the first questions was:
he described to me a game called othelo (http://en.wikipedia.org/wiki/Reversi) which is a 2 player board game using for example X and O, if player X placed X in an empty space
_OOOX
the O's between the two X's will be converted to X
XOOOX ==> XXXXX
this will happen on the current row, column, and the two diagonals in every directions
and if the following case happened
__OOX
and the X player placed X in the first space
X_OOX
nothing occured for the two Os
given a certain state of the board, location on the board, a certain piece
to place on the given location
update the board, and make the required validations
Then I started to code the required method, then have revised it and fixed small bugs, then he told me that it seems to be working.
then we turned to the second question:
which is given a Collection<String> words, return a Collection<String> of anagrams found in the given collection for example "The rat fell in the tar" => returned [rat tar]
Then I have discussed him in an algorithm with O(n k lg k) where n is the number of words and k is the average length of the word, then I started to code it and then he said that it seems to be working.
then the interview is finished.
Notes:
* Try to practice a lot before the interview, by solving such problems and try to mimic the interview environment by coding in the collabedit.com text editor
* Don't use Ctrl + S while coding in collabedit as it may lead to some problems.
* Don't be afraid before the interview, just calm down as the interviewers are very friendly.
Good Luck :)| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer - 1of 1 vote
Answersgiven a set of distinct integers {a1, a2, a3, a4, a5, ...}
- Anonymous December 22, 2010
and a set of exclusion rules: R = {{a1, a3}, {a2, a4, a10}, ...}
can you print out all the valid subsets?
Example:
what is a valid subset? {a1, a4}
what is an invalid subset? {a1, a2, a4}| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 0of 0 votes
AnswersConvert an ASCII representation of a positive integer to it's numeric value
- JL December 14, 2010| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer String Manipulation - 0of 0 votes
AnswersFind the minimum depth of a binary tree
- Ravi December 12, 2010| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Data Structures - 0of 0 votes
AnswersWrite a function to find the depth of a binary search tree
- Ravi December 09, 2010| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Data Structures - 0of 0 votes
AnswersGiven a unordered array of numbers, remove the fewest number of numbers to produce the longest ordered sequence. Print count of fewest numbers to be removed, and the remaining sequence.
- Anonymous November 30, 2010
For example, if input is 1 2 3 4 5 6 7 8 9 10, no (zero) numbers are removed, and input is the longest sequence.
If input is, 1 2 3 8 10 5 6 7 12 9 4 0, then fewest number of elements to be removed is 5 is the fewest number to be removed, and the longest sequence is 1 2 3 5 6 7 12.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 0of 0 votes
AnswersPrint an arbitrary tree, level by level
- rr November 22, 2010| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 1of 1 vote
AnswersPrint out all the subsets of an array
- rr November 22, 2010| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 0of 0 votes
AnswersTelephone Dir lookup:
- Cartman October 19, 2010
Given mapping: number to letters (just like on the telephone buttons)
i/p: digit string e.g. "1234"
1. o/p: all possible letter strings based on the mapping.
2. o/p only those strings that are in a given dictionary. (and length of the dictionary is small.)| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Coding - 0of 0 votes
AnswersImagine you are running a typical dropbox website (like x-drive) where users can upload their files/data. How will you go about monetizing this website using online advertising? What are the factors you will consider to match users to ads?
- Cartman October 19, 2010| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Ideas - 1of 1 vote
AnswersGiven a histogram of n items stacked next to each other, find the Max area under a given rectangle.
- Cartman October 19, 2010
Each bar in the histogram has width = 1 unit and hight is variable.
Hint: Brute force approach gives you O(n2) solution. Can you do better?| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 0of 0 votes
AnswersFind and delete nodes from a linked list with value=k. What's the complexity? Does it handle boundary cases?
- Cartman October 19, 2010
Hint: Make sure to free the memory when deleting a node using delete() or free()| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Linked Lists - 0of 0 votes
AnswersImplement Queue using stacks. What's the time complexity of various queue operations for this implementation?
- Cartman October 19, 2010| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Data Structures - 0of 0 votes
AnswersFind 2 numbers in an integer array that sum to x. If found return true else false.
- Cartman October 19, 2010
1. simple solution is O(n2)
2. Using certain data struct it can be improved to O(n) but you have to check for a special condition. what is that? Hint: if x = 4 and one of the values in the array is 2.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 1of 1 vote
Answers"Count and Say problem" Write a code to do following:
- Cartman October 19, 2010
n String to print
0 1
1 1 1
2 2 1
3 1 2 1 1
...
Base case: n = 0 print "1"
for n = 1, look at previous string and write number of times a digit is seen and the digit itself. In this case, digit 1 is seen 1 time in a row... so print "1 1"
for n = 2, digit 1 is seen two times in a row, so print "2 1"
for n = 3, digit 2 is seen 1 time and then digit 1 is seen 1 so print "1 2 1 1"
for n = 4 you will print "1 1 1 2 2 1"
Consider the numbers as integers for simplicity. e.g. if previous string is "10 1" then the next will be "1 10 1 1" and the next one will be "1 1 1 10 2 1"| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Coding - 0of 0 votes
AnswersSo the Problem being this.
- Prashanth October 13, 2010
Given a particular number say 637-8687 (NERVOUS) would be the word.
So for the older keypad’s seen on telephone’s I would have to create Mnemonics.
So for doing this, the first part being list out all the Permutations possible for a particular number series.
Ex: ListMnemonics(“723″) would result in
PAD PBD PCD QAD QBD QCD RAD RBD RCD SAD SBD SCD
PAE PBE PCE QAE QBE QCE RAE RBE RCE SAE SBE SCE
PAF PBF PCF QAF QBF QCF RAF RBF RCF SAF SBF SCF
For this my logic is
for the above number 723, somehow create all the permutations for 23 and then append for each of those permutations the letters of 7. That would give all the permutations possible for 723. The base case being if there is a single number then I would print its letters.
But please let me know what you guys think| Report Duplicate | Flag | PURGE
Facebook Front-end Software Engineer Algorithm - 0of 0 votes
AnswersInput a string and a pattern having . and *
- jiangok2006 October 02, 2010
Output: whether the string fully matches the pattern
. match any char, * means matching 0 or more times.
Example:
input "a", "." => match
input "abc", ".*" => match
input "abcd", "a.*d" => match| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 0of 0 votes
AnswersInput:
- jiangok2006 October 02, 2010
Either an object array having integer, string and boolean, like
{"abc", "ab,c", 10, true, false}
Or a hash table like
{"a1":"abc","t":true,"e":123}
Output:
If object array, output
"abc"
10
true
If hash, output
"a1":"abc"
"t" : true
"e" : 123| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 0of 0 votes
AnswersYou bought a carpet of size n*n, and when you got home you found it has white spots, and black spots (You don't know if it's a white carper with black spots, or a black carpet with white spots). A spot is one or more of the n*n 'cells', or the same color, with either a common side or a common corner. The 'original color' is that of which there are more spots.
- facebookista September 10, 2010
for example:
- if the carpet is all white, with a black circle in the middle, it's either black or white (as there is one white spot and one black spot)
- if the carpet is all white with a black, side to side, stripe in the middle, the carpet is white (as there are two whites, and one black spot)
- if it's a 'chessboard' pattern, it's again 1:1 (as each white has a common corner with another white...)
write a function:
int getOriginalColor(boolean[][])
that would return 0 for white, 1 for black, 2 for tie| Report Duplicate | Flag | PURGE
Facebook Front-end Software Engineer Algorithm - 0of 0 votes
AnswersSay you need to design a web application which needs to support friends of
- Anonymous August 27, 2010
friends function(like in linked in, when you search a person, it will show
you if this person is linked with you, your connection or your connections'
conection...), we expect to have millions of users and each user may have
thousands of friends, how would you design/implement this function to make
it scalable.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Ideas - 0of 0 votes
AnswersDesign Farmville,
- Anonymous August 10, 2010
Consider only crops and animals for now.
Whats classes will you have?
How will you handle interactions between various objects?
What design patterns can you use?
How will you handle millions of users?| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer - 0of 0 votes
AnswersHow will you design the backend for facebook. To handle millions of users. Explain the following transactions
- Anonymous July 27, 2010
1) Adding/Deleting a friend
2) Friend suggestions
What if you cannot store all users on one server?| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer - 0of 0 votes
AnswerGiven a 2D-grid map with several obstacles such as walls, doors and ones with other shapes, use A* algorithm to give the robot a path from point A to point B with fewest turns. Probability might be used in this problem.
- napozhu June 21, 2010| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 0of 0 votes
AnswersImplement copy-on-write string class.
- kuo February 27, 2010| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Coding