Every node k steps away
Write nodes_at_distance(root, start, k): return the values of every node exactly k edges away from the node start in a binary tree, in any order. Edges can be walked both ways, so the answer may include nodes above start and in other branches, not only below it; k = 0 gives just start, and a k larger than any distance gives []. Values are distinct, start is in the tree, and nodes have no link to their parent. Each TreeNode has val, left and right.
The tests call the provided run_nodes_at_distance(values, start, k), where values lists the tree level by level with null for a missing child ([1, null, 2, 3] is a root 1 with only a right child 2, whose left child is 3) and start is the value of the start node.
Examples
run_nodes_at_distance([8,4,12,2,6,10,14,1,3,5,7], 4, 2)→[12,1,3,5,7]run_nodes_at_distance([1,2,null,3,null,4,null,5], 3, 2)→[1,5]run_nodes_at_distance([8,4,12,2,6,10,14,1,3,5,7], 8, 0)→[8]