> For the complete documentation index, see [llms.txt](https://mayanktyagi3111.gitbook.io/interview-prep/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mayanktyagi3111.gitbook.io/interview-prep/trees/change-a-binary-tree-so-that-every-node-stores-sum-of-all-nodes-in-left-subtree.md).

# Change a Binary Tree so that every node stores sum of all nodes in left subtree

Given a Binary Tree, change the value in each node to sum of all the values in the nodes in the left subtree including its own.

**Examples:**

```
Input : 
     1
   /   \
  2     3

Output :
    3
  /   \
 2     3


Input
       1
      / \
     2   3
    / \   \
   4   5   6
Output:
      12
     / \
    6   3
   / \   \
  4   5   6
```

```java
class Solution {
    public int convertToLeftSumTree(Node node) {
        if (node == null)
            return 0;
        if (node.left == null && node.right == null) 
            return node.data;
        int left = convertToLeftSumTree(node.left);
        int right = convertToLeftSumTree(node.right);
        node.data += left;
        return node.data + right;
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://mayanktyagi3111.gitbook.io/interview-prep/trees/change-a-binary-tree-so-that-every-node-stores-sum-of-all-nodes-in-left-subtree.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.
