In method printUpwardPaths(), call to printUpwardPaths(cur.right, target, k) should not be made without checking the return value of printUpwardPaths(cur.left, target, k) first. The node is present only in either left or right subtree. If it is found in left-subtree, call should not be made to right sub-tree. Code as is will give correct result but does unnecessary processing.
Posts made by amit_sfo
RE: Find all nodes at distance K from a given target node in a binary tree