# Day 19: (Binary Tree)

[**Maximum path sum** ](https://leetcode.com/problems/binary-tree-maximum-path-sum/submissions/)\
Partially Solved on: Aug 5th 2020

```cpp
int helper(TreeNode* root, int res) {
    if (root==NULL) {
        return 0;
    }
    int ls = helper(root->left, res);
    int rs = helper(root->right, res);
    int max_single = max(max(ls, rs) + root->val, root->val);
    
    int max_top = max(max_single, ls+rs+root->val);
    
    res = max(max_single, max_top);
    
    return res;
}

int maxPathSum(TreeNode* root) {
    int res=INT_MIN;
    int ans = helper(root, res);
    
    return ans;
}    
```

[**Symmetric Tree**](https://leetcode.com/problems/symmetric-tree/)\
Solved on Aug 2nd 2020

```cpp
bool isSymmetric(TreeNode* root) {
        return isMirror(root, root);
}
    
bool isMirror(TreeNode* root1, TreeNode* root2) {
    if (root1 == NULL && root2 == NULL) {
        return true;
    }
    
    if (root1 && root2 && root1->val == root2->val) {
        return isMirror(root1->left, root2->right) && isMirror(root1->right, root2->left);        
    }
    return false;
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gopavasanth.gitbook.io/code/sde-problems/day-19-binary-tree.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
