Map<TreeNode, TreeNode> bfs(TreeNode x) {
        Queue<TreeNode> q = new LinkedList<>();
        q.add(x);
        Map<TreeNode, TreeNode> map = new HashMap<>();
        map.put(x, null);
        while (!q.isEmpty()) {
            TreeNode xx = q.remove();
            if (xx.left != null) {
                q.add(xx.left);
                map.put(xx.left, xx);
            }
            if (xx.right != null) {
                q.add(xx.right);
                map.put(xx.right, xx);
            }
        }
        return map;
    }
We first find path from root to p and from root to q nodes.
Then we traverse both paths till the values in arrays are same.
Return the common element just before the mismatch.
src/problems/medium/LowestCommonAncestorofaBinaryTree.java