Need help with "Chef learns BST"-ECAUG204

link to the problem: https://www.codechef.com/ENAU2020/problems/ECAUG204/

I don’t understand how to approach this problem.Can anyone help me with the approach.

Try to remember the properties of BST. There is a root node. And on the left, all values less than the key node are present and on the right, all values greater than key node are present.
So, to check whether an array presents a BST is to simply sort them in ascending order, which is also represents the inorder traversal of a BST(inorder traversal gives ascending order) and just check if there are unique elements

1 Like

thanks @ashish_kaur…i got it.

Only that much is sufficient

for _ in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    if len(set(l))==n:
        print('Yes')
    else:
        print('No')
1 Like