Facebook | onsite | E4 | USA
Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2021-04-16Added By Anonymous
Source: Link
Facebook | onsite | E4 | USA
...don't forget to upvote if you found it helpful :)...
`phone screen:`
https://leetcode.com/discuss/interview-question/1162082/facebook-or-phone-interview-or-E4-or-USA
All coding questions are either on leetcode or in other discuss posts. too lazy to find the question numbers
`coding 1:`
Q1: Check if array is a permutation of 0, 1, ..., n-1 (n is the length of the array)
Input: [0, 1, 2, 3]
Output: True
Input: [3, 1, 0, 2]
Output: True
Input: [0, 1, 4, 3, 6]
Output: False
Q2: reconstruct a tree from its inorder and preorder
Inorder: D B E A F C
Preorder: A B D E C F
A
/ \
/ \
B C
/ \ /
/ \ /
D E F
`coding 2:`
Q1. add two numbers represented by list
Input:
[3, 4, 5] -> 345
[9, 4] -> 94
Output:
[4, 3, 9] -> 439
Q2. return if you can partition a sentence using dictionary words (backtracking with memoization was enough for the interviewer, no need for trie)
`"whatisjava", => "what is java"`
`system design:`
https://leetcode.com/discuss/interview-question/1162048/facebook-or-system-design-or-onsite-or-E4-or-USA
`behavioral:`
copy the data from source to destination:
class Node {
char c[];
int len;
Node* next;
}
src: [fa] -> [ce] -> [bo] -> [ok]
dst (before): [aaaa] -> [aaaa] -> [aaaa]
dst (after): [face] -> [book] -> [aaaa]
Solution:
copy(Node* src, Node* dst) {
if (!src)
return;
Node* srcHead = src;
Node* dstHead = dst;
int sIndex = 0;
int dIndex = 0;
while (srcHead){
if (sIndex == srcHead->len){
srcHead = srcHead->next;
sIndex = 0;
contiune;
}
if (dIndex == dstHead->len){
dsrHead = dstHead->next;
dIndex = 0;
contiune;
}
dstHead->c[dIndex++] = srcHead->c[sIndex++];
}
}
followup: what if we have the below copy method:
memcpy(void* src, void* dst, int len);
Solution:
copy(Node* src, Node* dst) {
if (!src)
return;
Node* srcHead = src;
Node* dstHead = dst;
int sIndex = 0;
int dIndex = 0;
while (srcHead){
int cpyLen = min (srcHead->len-sIndex , dstHead->len-dIndex);
memcpy (srcHead , dstHead , cpyLen);
sIndex += cpyLen;
dIndex += cpyLen;
if (sIndex == srcHead->len){
sIndex = 0;
srcHead = srcHead->next;
}
if (dIndex == dstHead->len){
dIndex = 0;
dstHead = dstHead->next;
}
}
}
`followup interview (product architecture)`
design downloader library (only API design)
url of the file is given