Height of a Binary Tree

Medium Problems DSA practice problem on Onlearn.

Difficulty: medium.

Topics: How to determine the height (maximum depth) of a binary tree?, Binary Tree, Tree Traversal, Breadth-First Search, Recursion, complexity analysis, queue, binary tree, recursion, bfs, tree traversal.

Maximum Depth of Binary Tree Given the root of a binary tree, calculate its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. Input: The binary tree is represented in level order traversal format (BFS) with 1 indicating null/no child Output: A single integer representing the maximum depth Constraints: The number of nodes in the tree is in the range [0, 10^4] 1000 <= Node.val <= 1000 Example 1: Input: [1, 2, 5, 1, 1, 4, 6, 5] Output: 4 Explanation: The longest path is 1 → 5 → 4 → 5 Example 2: Input: [3, 1, 2] Output: 2 Explanation: The longest path is 3 → 1 or 3 → 2