Solution 15.5: missing corner case?

#1

The solution forgets to mention that both nodes are required to be present in the tree.
If it’s not the case then

  • the program will return “would-be” LCA (for example, for non-existing nodes with key 12 and 14 the node H(13) is returned)
  • NullPointerException is thrown (for example, for non-existing nodes with key 14 and 15)
1 Like

#2

Hey damluar,

As such topic is being discussed by many other readers, we won’t handle the situations that illegal cases (this is not corner cases in my opinion) since it will add many boilerplate codes that distract readers attention from the main algorithms. In the interview, most problems will not ask to deal with such cases for similar reason.

1 Like