public BinaryNode getIterative(BinaryNode root, BinaryNode n1, BinaryNode n2) {
    validateInput(root, n1, n2);

    List<BinaryNode> pathToA = getPathTo(root, n1);
    List<BinaryNode> pathToB = getPathTo(root, n2);
    BinaryNode result = null;
    int size = Math.min(pathToA.size(), pathToB.size());
    for (int i = 0; i < size; i++) {
      if (pathToA.get(i) != pathToB.get(i)) {
        result = pathToA.get(i - 1);
        break;
      }
    }
    return result;
  }
Iterative solution for this problem. The complexity order of this algorithm is the same in
memory terms, O(N), but is worst in space terms because we are using a list of BinaryNodes
that is going to suppose O(N) for space terms where N is the path to the element.

This algorithm is based on find the path of two nodes given a root node and compare both paths
to find the first non common element and return the previous node, the lowest common ancestor.
src/main/java/com/github/pedrovgs/problem21/LowestCommonAncestor.java