class LowestCommonAncestor {

  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;
  }

}