Question bank › Binary Search Tree
Dsa Binary Search Tree Easy

Unique Values in BST

Given the root of a binary search tree (BST), return the number of unique values in the tree. A unique value is defined as a value that appears only once in the tree. You should implement your solution using a traversal method and storing values in a set. Input format: The input consists of several lines. The first line contains an integer n, the number of nodes in the tree. The next n lines each contain an integer that represents the value of the node in the BST. Assume that the input is given in level order (breadth-first traversal). Output format: Print a single integer: the number of unique values in the BST. Example: Input: 5 3 1 4 3 6 Output: 4

Key concepts

binary_search_treetraversalset

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.