I interviewed with Facebook last month and got one interesting question:
Spread secret:
[A, B, 10]
[A, C, 20]
[B, D, 30]
[B, E, 5]
Source of secret: A
Here input means A talks to B and spread secret at time 10,etc.
Thus C will know secret at time 20, D will know at time 30.
However E doesnt' know because B talks to E at time 5 when B himself doesn't know secret.
Thus return a list of people who will know the secret at the end of day, answer will be [A, B, C, D]
I think this is not easy but also not hard. Solve it with BFS, just to compare time order when pushing into queue.
And now it's follow-up:
It's still the same relationship input, but now we know eventually it's [A, B, C, D] that get to know the secret, can you please return who's the source of secret? (Can be one or multiple)
Any thoughts on the follow-up question?