Skip to content

Latest commit

 

History

History
38 lines (33 loc) · 727 Bytes

File metadata and controls

38 lines (33 loc) · 727 Bytes

Lowest Common Ancestor

Challenge Description:

Write a program to determine the lowest common ancestor of two nodes in a binary search tree. You may hardcode the following binary search tree in your program:

    30
    |
  ____
  |   |
  8   52
  |
____
|   |
3  20
    |
   ____
  |   |
  10 29

Input sample:

The first argument is a path to a file that contains two values. These values represent two nodes within the tree, one per line. E.g.:

8 52
3 29

Output sample:

Print to stdout the lowest common ancestor, one per line. Lowest means the lowest depth in the tree, not the lowest value. E.g.:

30
8