Solution to create linked lists of all nodes at each depth of a tree