Dsa
Trees
Warm-up
Height of Binary Tree
Given a binary tree, compute its height. The height is the length of the longest path from the root to any leaf. A tree node is defined using a Node class with properties 'value', 'left', and 'right'. Write a function that reads the level-order traversal of the tree from input and prints the height of the tree.
Input format:
A single line of integers representing the level-order traversal of the tree (0 represents a null node).
Output format:
A single integer representing the height of the tree.
Example:
Input:
1 2 3 0 0 0 4
Output:
3
Key concepts
treesdepthrecursion
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