Question bank › Trees
Dsa Trees Warm-up

Count Leaf Nodes

Given a binary tree, count the number of leaf nodes in it. A leaf node is a node that has no children. You should read the tree in a specific format: first read an integer N, the number of nodes, followed by N lines where each line contains a node value and its left and right child indices (0 if there's no child). Print the count of leaf nodes. Example Input: 5 1 2 3 2 0 0 3 0 0 4 0 0 5 0 0 Example Output: 3

Key concepts

treesrecursioncounting

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.