> 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/check-whether-bst-contains-dead-end-or-not.md).

# Check whether BST contains Dead End or not

Given a [Binary search Tree](http://quiz.geeksforgeeks.org/binary-search-tree-set-1-search-and-insertion/) that contains positive integer values greater then 0. The task is to check whether the BST contains a dead end or not. Here Dead End means, we are not able to insert any element after that node.

**Examples:**

```
Input :        8
             /   \ 
           5      9
         /   \
        2     7
       /
      1               
Output : Yes
Explanation : Node "1" is the dead End because
         after that we cant insert any element.       

Input :       8
            /   \ 
           7     10
         /      /   \
        2      9     13

Output : Yes
Explanation : We can't insert any element at node 9.  
```

```java
class Solution {
    public boolean bstDeadEnd(Node node, int min, int max) {
        if (node == null)
            return false;
        if (node.data == min && node.data == max)
            return true;
        return bstDeadEnd(node.left, min, node.data - 1) || bstDeadEnd(node.right, node.data + 1, max);
    }

    public boolean deadEnd(Node node) {
        // As the given BST can only have positive Integers
        return bstDeadEnd(node, 1, Integer.MAX_VALUE);
    }
}
```


---

# 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/check-whether-bst-contains-dead-end-or-not.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.
