BST Check

0

0 votes
Easy
Problem

Given a BST with n nodes (to be constructed as in the previous question) in which all the nodes will be unique. Now given a query of the following format:

x y

where x and y are integers and query can be interpreted as, node with value x is to be changed with value y. Determine whether the resulting tree after processing the query is BST or not.

Input Format:

First line of input contains an integer t i.e. number of test cases. In the next t lines first line contains an integer n denoting number of nodes in the tree followed by n space separated integers. Then there will be two integers x and y.

Output Format:

For each test case, after processing the query, print "Yes" if the resulting tree is BST else print "No".

Constraints:

1 <= t <= 20

All other integers are well with in the integer range.

Note:

It is guranteed that the given query will be a valid one. Using an array to store tree elements is not allowed.

Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?