topological sort

Create tree from tuples

This is a coding problem from Uber onsite interview found here. Question: Given a list of pairs (tuples), each of them represents a connection from parent to it’s child in a tree. In this list, nodes will have edges not only for their direct children, but also all of it’s descendants (i.e. children’s children, and their children etc). If we have the following tree as an example: A / \ B C / \ D E Then the list given it will be