Screen:
Print all the peaks and valleys in an array with integers that are +/- 1 from its neighbors.
a[i] = a[i+1] +/-1
The edges of the array are not considered peaks/valleys.
E.g. 1,2,3,2,3,2 should print 3,2,3
Hint
This is doable in O(logN) RT in a sparse peak array.
Idea: #1539
Onsite:
Code 1:
https://leetcode.com/problems/valid-palindrome-ii/
https://leetcode.com/problems/basic-calculator-ii/ - only * and +. I was going to use stack, but the solution is a lot simpler.
Code 2:
Given a sorted array of integers, find the number of a specific integer.
E.g. [1,2,3,3,5], q=3 returns 2. There are 2 3's in the array.
[1,2,3,3,5], q=4 returns 0. There is no 4 in the array.
Not allowed to use built-in BS functions.
(I have made quite a few errors writing it down, but have fixed them all in the end)
https://leetcode.com/problems/word-break-ii/ - with 10 minutes left was able to give the exact outline code solution of the problem. I have solved this before.
Code 3:
https://leetcode.com/problems/subarray-sum-equals-k/ - just needed to answer if the sum exists.
https://leetcode.com/problems/binary-tree-vertical-order-traversal/
(implemented DFS, which was not correct. I think the interviewer did not notice or did not tell me. I almost went in to change it to BFS, but ran out of time. Have solved this before).
Behavior:
Standard questions
Coding: multiply 2 numbers.
Hint
Can easily be done in O(logN) via memoization.
System Design
Implement an analytics system to count ad views. The ad creators need to query for the total number of ad views in a certain period (min 1 min, max 2 years). The system might handle several thousand ad campaigns at a time.
Hint
Make sure to account for race conditions at the database level. Optimistic locking may be too inefficient. Build an additional subsystem to make sure unique ad campaign ids are serviced by a worker pool (queue requests?). Store intermediate results in separate databases not to hit the main Db at every view.
Info:
California, 10+ YOE
My advice:
Eat and sleep with recursion. Spice it up with DP.
Binary search comes up quite often too. So do DFS, BFS.
It should be second nature to pull out a recursion or a backtracking solution.
Conclusion:
I got rejected after almost solving every problem on the list. I felt that those problems were relatively easy. This was very depressing, as I have spent almost a year just on various FB interview preps. After doing this preliminary work, I am never again to spend more than a few days on an interview prep, agh! Life is too precious!
I think FB does itself a disservice by favoring people who can solve the problems quick versus those who can think deep. This process favors fast recall versus some thought process. Who could come up with those different array tricks from scratch in 5 minutes, for example?
I would suggest creating a group of intractable problems and giving people more time to try to come up with solutions. Then, really evaluate the thought process rather than whether the person has solved a problem and in how much time.


