Facebook Enterprise Engineer Phone/Screening Interview Dec 2021 - Amsterdam
Company: Meta (Facebook)
Role: Enterprise Engineer
Interview Stage: Phone/Screening Interview
Location: Amsterdam
Year: 2021
Original Post Content:
Hope this small post can help other candidates and have better luck than me :)
- 45 Minutes interview
- 2 coding exercises
Question1: Similar to 791. Custom Sort String, but input range is all Unicode characters and every letter on the "input" string is contained in the "order" string. This was my solution:
public String customSort(String input, String order) {
Map<Character, Integer> freq = new HashMap<>();
for(char c : input.toCharArray()) {
freq.merge(c, 1, Integer::sum);
}
StringBuilder sb = new StringBuilder();
for(char c : order.toCharArray()) {
int count = freq.get(c);
while(count > 0) {
sb.append(c);
count--;
}
}
return sb.toString();
}
Response from Interviewer: Asked about edge cases, answered that because of the restrictions there would be no special cases, even if both or one of the inputs are empty it would work. Seems to be satisfied with my answer.
Question2: Solve a mathematics expression using only * and + operators no parenthesis. For example:
String input = "42+10*2+4*3+4";
output: 78
Update: I thought of using a stack but interviewer wanted O(1) space solution.
Couldn't solve it in time, I had the main idea and code was about 80% done, but struggled to find the actual solution and at the end ran out of time :(
This is my solution I did after the interview:
public int solve(String input) {
int multiplication = 1;
int sum = 0;
int index = 0;
while (index < input.length()) {
StringBuilder sb = new StringBuilder();
while (index < input.length() && Character.isDigit(input.charAt(index))) {
sb.append(input.charAt(index));
index++;
}
if (index < input.length()) {
int val = Integer.parseInt(sb.toString());
char operator = input.charAt(index);
if (operator == '*') {
multiplication *= val;
} else {
// This must be "+" operator
sum += multiplication*val;
multiplication = 1;
}
} else {
multiplication *= Integer.parseInt(sb.toString());
}
index++;
}
sum += multiplication;
return sum;
}
Response from Interviewer: Said I was time out and asked if I had some questions for him, I said no. During the second question he threw some hints at me, was helpful but at the same time confusing.
Outcome: Still waiting, but honestly don't think they will continue the process. The interviewer was kind of emotionless and seemed to be doing something else while I was coding and explaining my ideas, which is really annoying talking to someone and they don't seem to care. I wish they would get more "friendly" or more helpful engineers, I guess lots of SE at Facebook are emotionless.
Update outcome: As expected, got rejected :'( . It actually wasn't that hard, I just had bad luck and couldn't think the actual solution for question2. Funny enough I actually solved the problem within 20 secs immediately after the interview ended, guess I hate interviews....