Facebook Interview Questions
- 0of 0 votes
Answer
- ajay.raj April 23, 2017 in United Statesclass Log{ String fun_name; String enterOrExit;// enter or exit int time; public Log(String fun_name, String enterOrExit, int time){ this. fun_name = fun_name; this. enterOrExit = enterOrExit; this.time = time; } } public void printInclusiveAndExclusiveTime (List<Log> logs){ } Log for some functions, calculate the inclusive time and exclusive time for each function E.g Fun_name enter / exit time F1 enter 1 F2 enter 2 F2 exit 3 F1 exit 4 F1: inclusive time = 4-1 = 3, exclusive time = 3-1 = 2 F2: inclusive time = 3-2 = 1, exclusive time = 1
| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
AnswersFind the subarray within an array (containing at least TWO number) which has the largest sum.
- ajay.raj April 20, 2017 in United States
For example, given the array [-2,-1,-3,-4,-1],
the contiguous subarray [-2,-1] has the largest sum = -3.
try to do it in O(n) time
Followup, if input is stream, how to solve it
public int maxSubArray(int[] nums) {}| Report Duplicate | Flag | PURGE
Facebook Software Engineer - 7of 7 votes
AnswersFacebook Senior Engineer On-site 2017
- aonecoding April 17, 2017 in United States
1st Round
Question 1: Binary tree to doubly linked list.
Question 2: Read 4 (Given the read4 API, read an entire file)
2nd Round
Culture fit. No coding.
3rd Round
Question: System Design POI (Point of Interest. Given a point, find things within a radius).
Lunch
4th Round
Question 1: Decode way
Question 2: Random max index
5th Round
Question: System design + component-wise design on download manager| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 4of 4 votes
AnswersGroup by with having related questions. ER provided was customer table.
- harshvp April 12, 2017 in United States for Search| Report Duplicate | Flag | PURGE
Facebook Data Engineer Database - 0of 0 votes
AnswersFind the % of all male customers in a specific area out of all the customers in that area.
- harshvp April 12, 2017 in United States for Search| Report Duplicate | Flag | PURGE
Facebook Data Engineer Database - 0of 0 votes
AnswersGet total number of all the departments of each employees
- harshvp April 12, 2017 in United States for Search| Report Duplicate | Flag | PURGE
Facebook Data Engineer Database - 0of 0 votes
AnswersA "derangement" of a sequence is a permutation where no element appears in its original position. For example ECABD is a derangement of ABCDE, given a string, may contain duplicate char, please out put all the derangement
- ajay.raj April 10, 2017 in United States
public List<char[]> getDerangement(char[]){}| Report Duplicate | Flag | PURGE
Facebook SDE1 - -2of 2 votes
Answersthree sum with duplicate, pirnt all indexes, for example:
- ajay.raj April 08, 2017 in United States
0 2 -2 -2
(0)(1)(2)(3)
print (0, 1, 2) (0, 1, 3)
can you do it use n^2 (or less) time complexity with as less space as possible?
public List<List<Integer>> threeSum(int[] nums) {}| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
AnswersGiven an array of integers:
- xjohnwu April 07, 2017 in UK
1. rearrange the array such that all non-zero members appear on the left of the array (order is not important)
2. return the number of non-zero members
e.g. [1,2,0,5,3,0,4,0] => [1,2,5,3,4,0,0,0] and return 5. The non-zero array members can be in any order.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 0of 2 votes
AnswersGiven an array of task and k wait time for which a repeated task
- ajay.raj April 06, 2017 in United States
needs to wait k time to execute again. please rearrange the task
sequences to minimize the total time to finish all the tasks.
Example
Tasks = 111222, k = 2,
One possible task sequence is
12_12_12,
another possible task sequence is 21_21_21
thus you shoud return 8
public int getMiniTime(int[] nums, int k){
}
follow up, output one of the sequence 12_12_12, or 21_21_21| Report Duplicate | Flag | PURGE
Facebook SDE1 - 1of 1 vote
AnswersGiven an unsorted array, sort it in such a way that the first
- ajay.raj April 06, 2017 in United States
element is the largest value, the second element is the smallest,
the third element is the second largest element and so on.
[2, 4, 3, 5, 1] -> [5, 1, 4, 2, 3]
can you do it without using extra space
public void sortAlternate(int[] nums){}| Report Duplicate | Flag | PURGE
Facebook SDET - 0of 0 votes
AnswersGiven a number of tasks (T) and servers (S), find out if the tasks can be accommodated on the servers. Each Task has a number of Units and each server has a number of Slots on which Units can run.
- ajay.raj April 04, 2017 in United States
The only condition is that two Units of the same Task "cannot" run on the same Server.
Servers
S[0] = "SS1", "SS2", "SS3", SS4 //Slots // 4 -> 3 -> 2 -> 1
S[1] = "SS1", "SS2" // 2 -> 1 -> 0 -> false
S[2] = "SS1", "SS2", SS3, SS4, SS5 // 5 -> 4 -> 3 -> 2
S[3] = "SS1", "SS2", SS3, SS4, SS5 // 5 -> 4 -> 3 -> 2
Example:
S[0] = 4
S[1] = 3
S[2] = 5
S[3] = 5
...
Tasks
T[0] = U0, U1, U2, U3 //Tasks
T[1] = U0, U1
T[2] = U0, U1, U2
...
Example:
T[0] = 4
T[1] = 2
T[2] = 3
implement
boolean boolean CanRunTasks(S[], T[]){
}| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
Answersclass UndirectedGraphNode { int label; List<UndirectedGraphNode> neighbors; UndirectedGraphNode(int x) { label = x; neighbors = new ArrayList<>(); } } public boolean isBipartite(List<UndirectedGraphNode> nodes){ }
use DFS algorithm to check the bipartite-ness of a graph
- ajay.raj April 04, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook SDE1 - 1of 1 vote
AnswersGiven some email ids, and a similarity function which says whether two email ids are similar, determine all the sets of email ids that are similar to each other.
- Ray March 28, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 0of 0 votes
AnswersYou have a string consisting of open and closed parentheses, but parentheses may be imbalanced.
- Ray March 26, 2017 in United States
Make the parentheses balanced and return the new string.| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 0of 0 votes
AnswersDesign a system which takes in latitude and longitude and returns back closest 5 locations.
- Ray March 26, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer System Design - 2of 2 votes
AnswersGiven an array of integers greater than zero, find if it is possible to split it in two (without reordering the elements), such that the sum of the two resulting arrays is the same. Print the resulting arrays.
- eo March 21, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook Production Engineer Coding - 4of 4 votes
Answersthere is a bunch of tasks, each have different time to complete, task is independent, and then there are some workers,
- ajay.raj March 18, 2017 in United States
How to allocate tasks to these workers to minimize the total time to complete all the task. The tasks can be randomly picked from the task list.
Example
Task: 2,2,3,7, 1
Worker: 2.
Return 8, because the first worker can work on the first three tasks : 2 + 2 + 3 = 7, and the second worker can work on the last two tasks : 7 + 1 = 8, so the total time to finish all the task is 8.
public int getMini(int[] tasks, int k)| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
AnswerWe have a List of FlightRoute
public static class FlightRoute { String from; String to; int time; .... }
and write a function to find Shortest Path: findShorestPath(String start, String end, List<FlightRoute>routes)
- ewrhoqpqheow March 16, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook SDE1 Data Structures - 2of 2 votes
AnswersIterate over a singly linked list backwards. Call print on each node.
Example: The list A->B->C should print as
"C B A"class Node { public Node next; public String value; }
There are 4 solutions
- Nerd March 16, 2017 in Europe
1) recursive
2) iterative with O(n) memory
3) iterative with O(1) memory and O(n²) runtime
4) iterative with O(1) memory and O(n) runtime (for this solution the initial list may be modified)
Explain all 4 solutions and write the code for solutions 3 and 4| Report Duplicate | Flag | PURGE
Facebook Solutions Engineer Coding - 1of 1 vote
AnswersYou are given an array of integers.
- Nerd March 16, 2017 in Europe
Write an algorithm that brings all nonzero elements to the left of the array, and returns the number of nonzero elements.
The algorithm should operate in place, i.e. shouldn't create a new array.
The order of the nonzero elements does not matter. The numbers that remain in the right portion of the array can be anything.
Example:
given the array [ 1, 0, 2, 0, 0, 3, 4 ],
a possible answer is [ 4, 1, 3, 2, ?, ?, ? ], 4 non-zero elements, where "?" can be any number.
Code should have good complexity and minimize the number of writes to the array.| Report Duplicate | Flag | PURGE
Facebook Solutions Engineer Coding - 3of 3 votes
AnswersGiven:
- alvaroneirareyes March 12, 2017 in United States
a encoded to 1
b encoded to 2
....
z encoded to 26
You can translate a number to a string:
'123' can be translated to 'abc'
but also can be translated to 'aw','lc' which gives 3 total translations
'12' can be translated to 'ab' and 'l' -> 2 translations
Write a function to get the number of valid combinations from a number like '123123123'| Report Duplicate | Flag | PURGE
Facebook Software Engineer - 2of 2 votes
AnswersYou have a string of numbers, i.e. 123. You can insert a + or - sign in front of ever number, or you can leave it empty. Find all of the different possibilities, make the calculation and return the sum.
- twinmind March 03, 2017 in United States
For example;
+1+2+3 = 6
+12+3 = 15
+123 = 123
+1+23 = 24
...
-1-2-3 = 6
...
Return the sum of all the results.| Report Duplicate | Flag | PURGE
Facebook Software Developer Algorithm - 0of 0 votes
AnswersDesign a algorithm to initialize the board of Candy Crush Saga. With M x N board, Q types of candies. (Rules: no 3 for run after initialization, must contain at least one valid move at the beginning)
- ajay.raj March 01, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer - 0of 0 votes
AnswersGiven the newest 100 entries of a person's facebook newsfeed. How would you rank the entries. The (for the user) most important ones should be ranked first. Which features would you use and how do you train/improve your model (machine learning)?
- nn862 February 28, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook Research Scientist System Design - 1of 9 votes
AnswersQ: Weighted meeting room
Given a series of meetings, how to schedule them. Cannot attend more than a meeting at the same time. Goal is to find maximum weight subset of mutually non-overlap meetings.class Meeting: def __init__(self): self.startTime self.endTime self.weight
@concernedCoder
- aonecoding February 27, 2017 in United States
When you claim the questions as fake, provide evidence. These are no doubt questions asked in the coding interviews of the best companies and they definitely help interviewees to prepare for the interview.
Why do you have a problem with this?| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 2of 2 votes
Answersgiven preorder traversal [5,3,2,4,8,7,9] of a BST, how do we identify the leaf nodes without building the tree ?
- Raj February 16, 2017 in United States
@Anonymous Thanks for the reply!
Please try other use cases like, only single leaf node| Report Duplicate | Flag | PURGE
Facebook Software Engineer Data Structures - 3of 3 votes
AnswersGiven estimated stock quotes, in an array, print the maximum profit from a buy and sell. i.e [19, 22, 15, 35, 40, 10, 20] would show a profit of 25(40 -15). The sale must come after the buy. Solve this in O(N) time.
- mcg1coding February 13, 2017 in United States<?php function print_max_profit($arr){ if(count($arr) < 1) return 0; $len = sizeof($arr); $profit = 0; $least = $arr[0]; for($i = 0; $i < $len; $i++){ $least = min($least,$arr[$i]); $profit = max($profit, $arr[$i] - $least); } return $profit; }
| Report Duplicate | Flag | PURGE
Facebook Solutions Architect - 1of 1 vote
AnswersGiven a set of possibly overlapping rectangles in different levels (All of which are "not rotated", can be uniformly represented as (left-bottom,right-top) tuplets), return a minimal set of (non-rotated) non-overlapping rectangles, that occupy the same area.
- hulk February 09, 2017
The rectangle at lower level has more priority than at higher levels.| Report Duplicate | Flag | PURGE
Facebook Software Developer Algorithm Data Structures - 1of 1 vote
AnswersI got my interview yesterday and the problem they asked me was: Giving a method intToEnglish that receives an int as a parameter, how do you return its representation in english words. The number can be of any size but no more than around 2 billion since the parameter is an int 2ˆ32
- jorgevalbuena56 February 08, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook Android Engineer Algorithm