Question bank › Binary Search Tree
Dsa Binary Search Tree Warm-up

Count Nodes in BST

You are given the root of a binary search tree (BST). Your task is to write a function that counts the number of nodes in the tree. A BST is a tree in which for each node, all values in the left subtree are less, and all values in the right subtree are greater than the node's value. Input Format: The first line contains an integer N, the number of nodes in the BST. The next N lines each contain an integer value, representing the value of each node in the BST. The values are presented in the order of insertion into the tree. Output Format: Output a single integer, the count of nodes in the BST. Example: Input: 3 5 3 7 Output: 3

Key concepts

binary_search_treecountingtraversal

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 InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.