Dsa
Binary Search Tree
Warm-up
Count Leaves in BST
You are given the root of a binary search tree (BST). Write a program to count the number of leaf nodes in the tree. A leaf node is a node that does not have any children.
Input Format:
The input consists of an integer N - the number of nodes followed by N integers which represent the values of the nodes in the BST, one per line.
Output Format:
Output a single integer which is the count of leaf nodes in the BST.
Example:
Input:
5
3
1
4
2
5
Output:
2
Key concepts
binary_search_treerecursioncounting
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