Compute tree depth and meeting rooms
Company: Zest AI
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Onsite
Overview: This question evaluates skills in tree traversal and recursion for computing maximum depth of a binary tree, alongside interval scheduling and resource allocation for determining the minimum number of meeting rooms, testing reasoning about data structures such as trees and interval endpoints.
Read the full Zest AI Data Scientist interview experience this question came from
Maximum Depth of a Binary Tree
Constraints
- 0 <= number of nodes <= 100,000
- Node values fit in a 32-bit integer
- The tree may be a long single chain (highly unbalanced)
- An empty tree returns 0
Examples
Input: ([3, 9, 20, None, None, 15, 7],)
Expected Output: 3
Explanation: Root 3 -> right child 20 -> leaf 15 (or 7): the longest path has 3 nodes.
Input: ([],)
Expected Output: 0
Explanation: Empty tree has depth 0.
Hints
- Maximum depth equals the number of levels in a breadth-first traversal of the tree.
- A recursive depth-first solution is concise, but with up to 100,000 nodes a degenerate chain can overflow the call stack — prefer an iterative BFS or an explicit stack.
- When the input is a level-order array, you can reconstruct parent-to-child links in one left-to-right pass using a queue of parents, consuming two array slots (left, right) per parent and skipping nulls.
Minimum Number of Meeting Rooms
Constraints
- 0 <= number of intervals <= 100,000
- intervals[i] = [start, end) with start < end
- All times are integers
- Intervals are half-open: a meeting ending at t does not conflict with one starting at t
Examples
Input: ([[0, 30], [5, 10], [15, 20]],)
Expected Output: 2
Explanation: [0,30) overlaps both [5,10) and [15,20), so 2 rooms are needed; [5,10) and [15,20) don't overlap each other.
Input: ([[7, 10], [10, 12]],)
Expected Output: 1
Explanation: Half-open: the meeting ending at 10 does not conflict with the one starting at 10, so one room suffices.
Hints
- Decouple starts from ends: sort all start times and all end times into two separate sorted arrays.
- Sweep with two pointers. The maximum number of meetings that are simultaneously in progress is the answer.
- Because intervals are half-open, treat a start at time t as NON-conflicting with an end at time t — use a strict `start < end` comparison so the ending meeting frees its room first.