Test cases failing


my output is coming right but test case is failing

you are building BST in wrong manner
you have to take input and then insert in bst one by one
DON’T sort the array and then build tree
because in question is not mention to build tree by sorting

Like this

	node* insertnode(int d, node*startnode) {
		if (startnode == NULL) {
			node*nn = new node(d);
			return nn;
		}

		if (startnode->data > d) {
			startnode->left = insertnode(d, startnode->left);
		}

		else {
			startnode->right = insertnode(d, startnode->right);
		}
		return startnode;
	}
	void BuildTree(int *arr, int n) {
		for (int i = 0; i < n; i++) {
			rootnode = insertnode(arr[i], rootnode);
		}
	}