You are given a stream of sequence, and you have to print all the person in the same generation.
Alice -> Bob, Tom
Tom -> Jerry, PhillipFor this input, it would be
Gen 1: Alice
Gen 2: Bob, Tom
Gen 3: Jerry, PhillipThe 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 -> AliceSo now, the answer would be:
For this input, it would be
Gen 1: John
Gen 2: Alice
Gen 3: Bob, Tom
Gen 4: Jerry, PhillipThe question was quite vague, but became clear after asking relevant hints from the interviewer.