Solve BST range average and merge intervals
Company: Meta
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Technical Screen
Quick Answer: This question evaluates understanding of binary search tree properties and range-based traversal pruning for computing aggregates, together with techniques for merging two sorted interval lists into non-overlapping ranges, testing proficiency with tree and interval data structures and aggregate computation in the Coding & Algorithms domain.
BST Range Sum and Average
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: ([10,5,15,3,7,None,18], 7, 15)
Expected Output: {'sum': 32, 'average': 10.666666666666666}
Explanation: Range includes 7,10,15.
Input: ([5], 6, 9)
Expected Output: {'sum': 0, 'average': None}
Explanation: No values in range.
Input: ([], 1, 2)
Expected Output: {'sum': 0, 'average': None}
Explanation: Empty tree.
Hints
- Choose a representation that makes the requested operation direct.
- Handle empty inputs and boundary cases first.
Merge Two Sorted Interval Lists
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: ([[1,3],[8,10]], [[2,6],[15,18]])
Expected Output: [[1, 6], [8, 10], [15, 18]]
Explanation: Cross-list overlap.
Input: ([[1,3]], [[3,5]])
Expected Output: [[1, 5]]
Explanation: Touching intervals merge.
Input: ([], [[1,2]])
Expected Output: [[1, 2]]
Explanation: One list empty.
Hints
- Choose a representation that makes the requested operation direct.
- Handle empty inputs and boundary cases first.