So I have an input of the type:
but the problem is that the nodes and parent aren't given in a specific order starting from root, and I want to build a Trie but I can't because of this aspect, I thought about using a queue with Trie nodes, and when their parent appear I will pop them from the queue, but there is a problem since what if their parents are already in the queue? And I don't know how to solve this problem.. or to solve it efficiently
sample input: 1 0 0 -1 2 1 3 0 4 3
-1 as a parent means it is the root node, observe the order is random.