Facebook Interview Questions
- 1of 1 vote
AnswersImplement circular buffer with read & write functions
- aonecoding June 06, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer Data Structures - 1of 1 vote
AnswersCoding III
- aonecoding June 06, 2017 in United States
Implement int divide(int a, int b) without division or mod operation.
## Round IV
Behavioral Questions + Project Walk Through + Coding (Validate BST)
## System Design V
Design memcache to enable read, write and delete (single server, non-distributed infrastructure).
Which data structure to go with?
Eviction rules?
How to minimize segmentation?
How to handle concurrency?
## Extra
After two weeks they called me to an extra round of system design.
How to store social graphs?
How to handle concurrent read/write requests(read heavy) on one server.| Report Duplicate | Flag | PURGE
Facebook Software Engineer - 2of 2 votes
AnswersFind Famous person in the list of persons.
- Seeker June 01, 2017 in United States
A person is a famous person if he doesn't know anyone in the list and everyone else in the list should know this person.
The function isKnow(i,j) => true/ false is given to us. No need to worry about it.
Goal is to find the famous person in O(n) complexity.| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 0of 0 votes
Answers/* Find all subsets of size k in an array that sum up to target
- ajay.raj May 31, 2017 in United States
the array may contains negative number */
class Solution {
public List<List<Integer>> combinationSum(int[] nums, int target, int k) {
}| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
AnswersA bot is an id that visit the site m times in the last n seconds,
given a list of logs with id and time sorted by time, return all the bots's id
- ajay.raj May 31, 2017 in United Statesclass Log{ String id; int time; } public HashSet<String> getBots(Log[] logs, int m, int n){ }
| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
Answersdownload all urls from 1000 hosts. Imagine all the urls are graph.
- ajay.raj May 28, 2017 in United States
Requirement: Each host has bad internet connection among each other, Has to download url exacly once.| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
AnswerGive you a robot and a room where you do not know where the robot is in the room and you do not know the size of the room, you have a remote control that allows the robot to walk around four directions. Here you give a move method: boolean move (int direction), direction: 0,1,2,3 that four directions. If it can move in that direction, return true, and if it cannot move in that direction, return false. Ask you determine how big this room is. the shape of the room can be any shape, so you cannot assume it is rectangle or square.
- ajay.raj May 26, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook SDE1 - 1of 1 vote
AnswersGiven a 2D character array of size NxN. Find if there is a path from the cell 'R' to the cell 'T'. You can go left, right, up, down from a cell and you cannot pass through any cell marked with 'X'.
- Thor May 25, 2017 in United States
Example input:
X__R_X
X_XXX_
______
_XX_XX
XT__X_
Output: true| Report Duplicate | Flag | PURGE
Facebook Software Engineer - 0of 0 votes
AnswersPrint all permutations of a given string.
- Thor May 25, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer - 0of 0 votes
AnswersThere are N gas stations along a circular route, where the amount of gas at station i is gas[i].
- majia168 May 23, 2017 in United States
You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its next station (i+1). You can begin the journey with an empty tank at one of the gas stations.
Return ALL the starting gas station's index where you can travel around the circuit once
public List<Integer> canCompleteCircuit(int[] gas, int[] cost) {
}| Report Duplicate | Flag | PURGE
Facebook SDE1 - 1of 1 vote
AnswersYou have a array with integers:
[ 1, -2, 0, 6, 2, -4, 6, 6 ]
You need to write a function which will evenly return indexes of a max value in the array.
- vu-doo-cok May 22, 2017 in UK
In the example below max value is 6, and its positions are 3, 6 and 7. So each run function should return random index from the set.
Try to implement with O(n) for computation and memory.
Try to reduce memory complexity to O(1).| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 0of 0 votes
AnswersYou have a binary tree which consists of 0 or 1 in the way, that each node value is a LOGICAL AND between its children:
0 / \ 0 1 / \ / \ 0 1 1 1
You need to write a code, which will invert given LEAF and put tree in a correct state.
- vu-doo-cok May 22, 2017 in UK| Report Duplicate | Flag | PURGE
Facebook Software Engineer Data Structures - 0of 0 votes
AnswersGiven n1, n2 is the number after removing one digit from n1. Example, n1 = 123, then n2 can be 12, 13 or 23.
- ajay.raj May 22, 2017 in United States
If we know the sum of n1 + n2, and find the possible values of n1 and n2.
public List<List<Integer>> getNumber(int sum){
}| Report Duplicate | Flag | PURGE
Facebook SDE1 - -1of 1 vote
AnswersDesign copy-on-write string class
- ajay.raj May 22, 2017 in United States
e.g. stringclass s("abc");
stringclass s1 = s; // no copy
s = "bcd"; // copy| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
AnswerDesign and implement an algorithm to assign an unlimited M number of messages evenly among N number of servers (N will not change).
- aifra2000 May 20, 2017 in United States
Input to the algorithm
A message contains a message identifier and a text string. The algorithm will be fed one message at a time.
There are N numbers of servers (N will not change), each can be identified by a unique id.
Output of the algorithm
When the algorithm is called to process a message, it should output the id of the server that the message is assigned to.| Report Duplicate | Flag | PURGE
Facebook SDE-3 - 0of 0 votes
AnswersGiven an ODD number, print diamond pattern of stars recursively.
n = 5, Diamond shape is as follows: * *** ***** *** *
void print(int n){
- ajay.raj May 20, 2017 in United States
}| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
Answers/From the input array, output a subset array with numbers part of a Fibonacci series.
- ajay.raj May 20, 2017 in United States
// input: [4,2,8,5,20,1,40,13,23]
// output: [2,5,1,8,13]
public static List<Integer> getFibNumbers(int[] nums){}| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
AnswersThe number of valid combinations of a strings for given input array a[], where a=>1, z => 26, and 0 <= a[i] <= 9
- nelly2k May 19, 2017 in United States
{1,1,1} => {aaa, ak, ka} => 3
{1,1,0} => {aj} => 1| Report Duplicate | Flag | PURGE
Facebook SDE-2 Algorithm - 0of 0 votes
AnswersCan multiple threads improve the time complexity to merge k sorted arrays? If so, how?
- ajay.raj May 18, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook SDE1 Arrays - 0of 0 votes
AnswersGives an array of unsorted int (may have negative number),
- ajay.raj May 15, 2017 in United States
rearrange the array such that the
num at the odd index is greater than the num at the even index.
example
giving 5, 2, 3, 4, 1, one of the expected result is 1,4,2,5,3,
please solve it in o(n) time, where n is the length of the array
public void rearrange(int[] nums){
}| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
Answers
- ajay.raj May 15, 2017 in United StatesGiven a string, find all possible combinations of the upper and lower case of each Alphabet char, keep the none Alphabet char as it is. example1 s = "ab", return: "Ab", "ab", "aB", "AB" example2 s = "a1b", return: "A1b", "a1b", "a1B", "A1B" public List<String> getPermutation(String s){ }
| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
AnswersGiven a binary tree of integers, write code to store the tree into a list of integers and recreate the original tree from a list of integers.
- Null0 May 13, 2017
Here's what your method signatures should look like (in Java):
List<Integer> store(Node root)
Node restore(List<Integer> list)
Example Tree:
5
/ \
3 2
/ / \
1 6 1| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm Data Structures Java Trees and Graphs - 0of 0 votes
AnswersFor a given array, find the subarray (containing at least k number) which has the largest sum.
- ajay.raj May 13, 2017 in United States
Example:
// [-4, -2, 1, -3], k = 2, return -1, and the subarray is [-2, 1]
// [1, 1, 1, 1, 1, 1], k = 3, return 6, and the subarray is [1, 1, 1, 1, 1, 1]
try to do it in O(n) time
Followup, if input is stream, how to solve it
public int maxSubArray(int[] nums, int k) {}| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
Answersfind maximum contiguous subarray sum with size (the number of the element in the subarray) <= k
- ajay.raj May 12, 2017 in United States
a brute force method is very simple, can you do it better?
public int maxSum(int[] nums, int k){
}| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
AnswersI want to learn some big words so people think I'm smart.
- Ajibz May 11, 2017 in United States
I opened up a dictionary to a page in the middle and started flipping through, looking for words I didn't know. I put each word I didn't know at increasing indices in a huge array I created in memory. When I reached the end of the dictionary, I started from the beginning and did the same thing until I reached the page I started at.
Now I have an array of words that are mostly alphabetical, except they start somewhere in the middle of the alphabet, reach the end, and then start from the beginning of the alphabet. In other words, this is an alphabetically ordered array that has been "rotated." For example:
String[] words = new String[]{
"ptolemaic",
"retrograde",
"supplant",
"undulate",
"xenoepist",
"asymptote", // <-- rotates here!
"babka",
"banoffee",
"engender",
"karpatka",
"othellolagkage",
};
Write a function for finding the index of the "rotation point," which is where I started working from the beginning of the dictionary. This array is huge (there are lots of words I don't know) so we want to be efficient here.| Report Duplicate | Flag | PURGE
Facebook Development Support Engineer Sorting - 0of 0 votes
Answers// Read4K - Given a function which reads from a file or
- ajay.raj May 11, 2017 in United States
// network stream up to 4k at a time, give a function which
// which can satisfy requests for arbitrary amounts of data
private int read4K(char[] buf) {
// GIVEN
}
// IMPLEMENT:
public int read(char[] buf, int toRead) { }
Due to network latency, if the read4K method return a value < 4k, it does not necessarily mean that we reach the End of File (EOF), in this case, you should continue to read the file until you reach toRead or EOF.| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
Answersgiven a graph: example -> A company holds 10% of B company’s share,
- ajay.raj May 11, 2017 in United States
B company holds 5% of C company’s share, A company holds 2% of C company’s share,
what percent of C company’s share does A company hold?| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
Answers
- ajay.raj May 11, 2017 in United States// Design and implement key value system // // string -> string // Insert a key-value pair or modify a value void put(string key, string value); // Delete a key-value pair void delete(string key); // Gets a value given a snapshot string get(string key, Snapshot snap); // Take a snapshot Snapshot takeSnapshot(); // Delete a snapshot void deleteSnapshot(Snapshot snap); // put(k1,v1) // put(k2,v2) // put(k3,v3) // takeSnapshot -> snap1 { k1 -> v1, k2 -> v2, k3 -> v3 } // get(k1,snap1) -> v1 // put(k1,v4) // delete(k3) // takeSnapshot -> snap2 { k1 -> v4, k2 -> v2 } // get(k1,snap2) -> v4 // get(k1,snap1) -> v1 // get(k3,snap2) -> XX // deleteSnapshot(snap1) // get(k1,snap1) -> XX // Space efficient is more important than time efficient, thus please use as small space as possible.
| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
AnswersInsert node with a given value in a circular sorted linked list.
- sbdul May 10, 2017 in UK| Report Duplicate | Flag | PURGE
Facebook Software Engineer Intern - 0of 0 votes
AnswersGiven list of N points find the K closest points to origin i.e((0,0)).
- sbdul May 10, 2017 in UK| Report Duplicate | Flag | PURGE
Facebook Software Engineer Intern
Open Chat in New Window