@@ -0,0 +1,1547 @@
+package com.ttaylorr.ctci.answers.trees;%0A%0Aimport com.ttaylorr.ctci.answers.trees.util.TreeNode;%0Aimport com.ttaylorr.ctci.meta.Solution;%0A%0A@Solution(chapter = 4, problem = 6)%0Apublic class CommonAncestor %7B%0A    // Example usage: CommonAncestorFinder.of(foo, bar).in(baz);%0A    public static CommonAncestor.Builder of(TreeNode a, TreeNode b) %7B%0A        return new CommonAncestor.Builder(a, b);%0A    %7D%0A%0A    private static class Builder %7B%0A        private TreeNode a, b;%0A        public Builder(TreeNode a, TreeNode b) %7B%0A            this.a = a;%0A            this.b = b;%0A        %7D%0A%0A        public TreeNode in(TreeNode root) %7B%0A            return new CommonAncestor(a, b).findCommonAncestor(root);%0A        %7D%0A    %7D%0A%0A    protected final TreeNode a, b;%0A    public CommonAncestor(TreeNode a, TreeNode b) %7B%0A        this.a = a;%0A        this.b = b;%0A    %7D%0A%0A    public TreeNode findCommonAncestor(TreeNode root) %7B%0A        if (this.covers(root.left, this.a) && this.covers(root.left, this.b)) %7B%0A            return this.findCommonAncestor(root.left);%0A        %7D else if (this.covers(root.right, this.a) && this.covers(root.right, this.b)) %7B%0A            return this.findCommonAncestor(root.right);%0A        %7D else %7B%0A            return root;%0A        %7D%0A    %7D%0A%0A    /**%0A     * Determine whether the other node is contained within the root.%0A     */%0A    private boolean covers(TreeNode root, TreeNode other) %7B%0A        if (root == null) return false;%0A        if (root == other) return true;%0A        else return this.covers(root.left, other) %7C%7C this.covers(root.right, other);%0A    %7D%0A%7D%0A

Add finding the common ancestor problem