Facebook Interview Questions
- 0of 0 votes
AnswersTake a tree (binary or otherwise), write a method in any language that, when given the root node, will print out the tree in level order. With a new line after the end of every level.
- Jason Jiang February 25, 2010
Helper methods are ok, big O run time efficiency doesn't matter (though obviously a quicker solution is better). Do not destroy original tree.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Trees and Graphs - 0of 0 votes
AnswersWrite code for finding length of largest monotonically increasing sequence in an array of integers.
- Anonymous February 22, 2010
Optimize it (not the usual O(n) in worst case, but a better approach in average case).| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 0of 0 votes
AnswersWrite a program to find the square root of a given number.
- BA October 21, 2009
He wanted some kind of binary search.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 0of 0 votes
AnswersHas anyone tried this? http://www.facebook.com/careers/puzzles.php?puzzle_id=11
- tadbooch11 June 18, 2009
The brute force way is n! so definitely won't scale. I tried a little bit of pruning (where I keep track of expected time and as soon as I see that it's more than then current minimum expected time, I bail out). But other than that, can't think of any..
So here is I have uptill now:
for all permutations of possible paths:
find expected time for that shortest path
if (there is a path) and (expected time < min expected time)
minexpectedtime = expectedtime.
Can someone give me hints on pruning? I think I need a better way than going through all the permutations but am unable to think? Any help on algorithms/pruning/datastructure would be appreciated..| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm Data Structures - 0of 0 votes
AnswersUser Bin Crash
- CUNOMAD May 18, 2009
You are on a cargo plane full of commercial goods when the pilot announces that the plane is short on fuel. Unless cargo is ejected from the plane, you will run out of fuel and crash. The pilot provides you with the number of pounds of weight that must be ejected from the plane. Fortunately, the manifest of the plane is both completely accurate, digitized, and you are a programmer of some repute. Unfortunately, your boss is going to be extremely unhappy, and wants you to exactly minimize the losses to the absolute minimum possible without crashing the plane. The manifest does not contain the exact quantities of every type of good, because you have so many on board. You may assume that you will not run out of any good in the course of saving the plane. You also realize this kind of program could be handy to others who find themselves in similar situations.
Write a program that takes a single argument on the command line. This argument must be a file name, which contains the input data. The program should output to standard out the minimum losses your boss will incur from your ejection of goods (see below). Your program will be tested against several manifests of several crashing planes; each with different data. Additionally, your program must be fast, and give the correct answer.
Input specifications
The input file will start with an integer number indicating the minimum number of pounds of weight that must be ejected from the plane to prevent a crash, followed by a new line. Each additional line in the file represents a commercial SKU (stock keeping unit) along with its cost (in dollars) and weight (in pounds). The format of these lines is:
<SKU label> <weight in pounds> <cost in dollars>
SKUs are represented as a combination of letters (upper and lower case) and numbers. Both costs and weights are integers. Each piece of data in a line is separated by white space. Lines are separated by a single new line character. You are guaranteed your program will run against well formed input files.
Example input file:
1250
LJS93K 1300 10500
J38ZZ9 700 4750
HJ394L 200 3250
O1IE82 75 10250
Output specifications
Your boss is not interested in exactly what you ejected to save the plane, he/she is currently only interested in how much it will cost the company. Your program must find the set of goods that will prevent the plane from crashing, and minimize company losses. It should print out the total value of goods lost as a plain integer, followed by a newline. Do not insert commas or dollar signs.
Example output (newline after integer):
9500| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 0of 0 votes
AnswersCompute the square root of a function
- Anonymous April 17, 2009| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Coding - 0of 0 votes
AnswersWrite a function to identify if an integer has the same value when reversed (i.e flipped over. 6 when reversed will be 9).
- Anonymous February 28, 2009
For ex : the method should return true for the following integers
818
1691
88
but should return false for
8018
212| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Coding - 0of 0 votes
Answerswrite a sql to find all the duplicate email address in a table which contains only one column "email"
- Mo February 28, 2009| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Database - 0of 0 votes
AnswersWrite a program to reverse a string and use it as a subroutine to reverse each word in a line
- Devil170 February 28, 2009| Report Duplicate | Flag | PURGE
Facebook String Manipulation - 1of 1 vote
AnswersWrite a program to evaluate a simple mathematical expression like 4 + 2*a/b - 3
- Devil170 February 28, 2009| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 1of 1 vote
AnswersWrite a progam to rotate a matrix by 90 degrees.
- Devil170 February 28, 2009| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Matrix - 1of 5 votes
AnswersDivide a list of numbers into group of consecutive numbers but their original order should be preserved?
- rhine November 23, 2008
e.g.
8,2,4,7,1,0,3,6
2,4,1,0,3 and 8,7,6
obviously in shortest time and space.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 0of 0 votes
AnswersWrite a method in C to reverse a linked list.
- Andy November 13, 2008| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Terminology & Trivia Linked Lists - 0of 0 votes
AnswersCode a function 'dedupe' that removes duplicate characters from a string.
- Facebook July 15, 2008| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Coding - 0of 0 votes
AnswersTell me about a recent bug you tracked down and how you did it.
- Facebook July 15, 2008| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Experience - 0of 0 votes
AnswersWhats the difference between statically and dynamically typed languages?
- Facebook July 14, 2008| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Terminology & Trivia