---
# System prepended metadata

title: Umee Interview

---

# Umee Interview

write a function (pseudocode) to find the last common ancestor of two nodes:

```typescript
class Tree {
  node: Node | Leaf
}
class Node {
  left:  Tree
  right: Tree
  value: string
}
class Leaf {}

function lca(n1: Node, n2: Node, root: Node): Node {
  ...
}
```

example:
```
        a
      /   \
     c    null
    / \
  d    e
      / \
     f   null

lca (f, d, a) =  c
lca (f, e, a) =  e
```