You’re interviewing for a backend or data engineering role at a FAANG-level company. The interviewer describes a real product scenario:
A large-scale system represents hierarchical structures such as organization charts, feature dependencies, decision trees, or file systems using binary trees.
To estimate processing complexity, memory usage, or recursion limits, the system often needs to compute how deep the tree goes. This depth determines:
- worst-case traversal cost
- recursion stack size
- tree balance indicators
- performance characteristics
The maximum depth of a binary tree is defined as the number of nodes along the longest path from the root node down to the farthest leaf node.
This is a common practice coding problem for DSA question might ask in Google, Amazon, Netflix, Meta, Apple, Microsoft, Uber, and Bloomberg interviews.
Your Task
Given the root of a binary tree, return its maximum depth.
Input Format
root: the root node of a binary tree
Each node is defined as:
TreeNode { int val; TreeNode left; TreeNode right; }
Output Format
- A single integer representing the maximum depth of the binary tree