

Ninja was playing with the nodes of the BST (Binary Search Tree). He found that after insertion of some nodes, he was unable to insert any more nodes to a leaf node. In such a scenario he termed the BST as Dead End. He has many sets of BST, it is very difficult for him to individually find whether a BST is Dead End or not. He asked you to design an algorithm to find whether a given Binary Search Tree (BST) containing positive integers only is Dead End or not.
Note: A BST is said to be Dead End if there exists a leaf node in the BST, for which it is impossible to insert any further nodes after that node in that BST. If such nodes do not exist, then the BST is not said to be Dead End.
A binary search tree (BST) is a binary tree data structure with the following properties.
• The left subtree of a node contains only nodes with data less than the node’s data.
• The right subtree of a node contains only nodes with data greater than the node’s data.
• Both the left and right subtrees must also be binary search trees.
The first line of input contains a single integer T, representing the number of test cases or queries to be run.
Then the T test cases follow.
The first and only line of each test case contains elements in the level order form. The line consists of values of nodes separated by a single space. In case a node is null, we take -1 in its place.
For example, the input for the tree depicted in the below image would be :
4
2 6
1 3 5 7
-1 -1 -1 -1 -1 -1 -1 -1
Explanation :
Level 1 :
The root node of the tree is 4
Level 2 :
Left child of 4 = 2
Right child of 4 = 6
Level 3 :
Left child of 2 = 1
Right child of 2 = 3
Left child of 6 = 5
Right child of 6 = 7
Level 4 :
Left child of 1 = null (-1)
Right child of 1 = null (-1)
Left child of 3 = null (-1)
Right child of 3 = null (-1)
Left child of 5 = null (-1)
Right child of 5 = null (-1)
Left child of 7 = null (-1)
Right child of 7 = null (-1)
The first not-null node (of the previous level) is treated as the parent of the first two nodes of the current level. The second not-null node (of the previous level) is treated as the parent node for the next two nodes of the current level and so on.
The input ends when all nodes at the last level are null (-1).
Note :
The above format was just to provide clarity on how the input is formed for a given tree.
The sequence will be put together in a single line separated by a single space. Hence, for the above-depicted tree, the input will be given as:
4 2 6 1 3 5 7 -1 -1 -1 -1 -1 -1 -1 -1
Output format :
For each test case, print a single line containing "True" if BST is Dead End else "False" (without quotes).
Output for each test case will be printed in a separate line.
Note :
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 100
1 <= N <= 5000
1 <= node data <= 10^9, (where node data != -1)
Time Limit: 1 second
2
10 5 12 -1 9 -1 15 -1 -1 -1 -1
7 4 8 -1 -1 -1 -1
True
False
For the first test case, the given BST is depicted below.

We can observe that we cannot insert any node after the node having the data 9. So this BST is Dead End.
For the second test case, the given BST is depicted below.

New nodes can be inserted after all the leaf nodes like we can insert 5 after 4 and 9 after 8. So this BST is not Dead End.
2
5 3 7 -1 -1 6 8 -1 -1 -1 -1
2 1 -1 -1 -1
True
True