> For the complete documentation index, see [llms.txt](https://programming.arora-aditya.com/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://programming.arora-aditya.com/leetcode/tree/897.-increasing-order-search-tree.md).

# 897. Increasing Order Search Tree

## Approach 1: In-order tree traversal

We simply store the node values one by one from the tree using the in-order tree traversal and once we are done we can simply generate a tree in the required configuration

```python
# Definition for a binary tree node.
# class TreeNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution(object):
    def inorderTraversal(self, root):
        """
        https://leetcode.com/problems/binary-tree-inorder-traversal/description/
        :type root: TreeNode
        :rtype: List[int]
        """
        res, stack = [], []
        while True:
            while root:
                stack.append(root)
                root = root.left
            if not stack:
                return res
            node = stack.pop()
            res.append(node.val)
            root = node.right

    def increasingBST(self, root):
        """
        :type root: TreeNode
        :rtype: TreeNode
        """
        l = self.inorderTraversal(root)
        rootCopy = TreeNode(l[0])
        traverse = rootCopy
        for i in l[1:]:
            traverse.left = None
            traverse.right = TreeNode(i)
            traverse = traverse.right
        return rootCopy
```

> **Time Complexity:** *O(N) \[number of node is N]*
>
> **Space Complexity:** *O(N)*


---

# 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://programming.arora-aditya.com/leetcode/tree/897.-increasing-order-search-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.
