Amazon | Onsite | Print the people at each generations for a stream of data
Anonymous User
1516

You are given a stream of sequence, and you have to print all the person in the same generation.

Alice -> Bob, Tom
Tom -> Jerry, Phillip

For this input, it would be

Gen 1: Alice
Gen 2: Bob, Tom
Gen 3: Jerry, Phillip

The question was quite clear (using topological sorting) if the data was a static, but the interviewer mentioned that it's a stream of data.

So later on, another data can come in with something like this:

John -> Alice

So now, the answer would be:
For this input, it would be

Gen 1: John
Gen 2: Alice
Gen 3: Bob, Tom
Gen 4: Jerry, Phillip

The question was quite vague, but became clear after asking relevant hints from the interviewer.

Comments (6)