Word break and lowest common ancestor in binary tree