Ambigious question statement

this question statement is not very clear and according to what i have understood this question can have multiple answers

Hello @sudipt1999,

No, that’s not the case:

Possible approach:
First, store all the names of the beverages, as they appear on the input, in a list A. It might be better to map the names to an integer and also map the integer back to the name of the beverage. Then create a directed graph G denoting the dependency between the beverages, where the nodes in the graph represent the names of the beverages. Keep track of the in degree of all the nodes in the graph.

iterate all the nodes (beverages) in the order given in list A.

Take the first node u in list A whose in degree is zero and insert the node to a list T which represents the topologically sorted beverages.

Decrease the in degree of all the node v by one, where the ordered pair (u,v) represents an edge of the graph G. Discard node u from list A.

Again start from the beginning of A and take the first node out whose in degree is zero and insert into the list T. Keep doing this until all the nodes are discarded from A and inserted into T.

The list T now gives the order of the beverages in the desired order.

You can have a look at this code for an idea:

Hope, this would help.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.