Solve meeting and tree problems
Company: Bloomberg
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Technical Screen
Quick Answer: This question evaluates skills in interval manipulation and boolean-based merging, along with binary-tree traversal and side-view extraction for string construction, assessing data-structure proficiency and algorithmic reasoning.
Part 1: Merge Meeting Intervals
Constraints
- `0 <= len(intervals) <= 200000`
- `-10^9 <= start <= end <= 10^9`
- Intervals are closed for merging purposes: if `next_start == current_end`, they merge.
Examples
Input: [[5, 7], [1, 3], [2, 4], [8, 10]]
Expected Output: [[1, 4], [5, 7], [8, 10]]
Explanation: `[1, 3]` and `[2, 4]` overlap, so they merge into `[1, 4]`.
Input: [[1, 3], [3, 5], [6, 8], [7, 9]]
Expected Output: [[1, 5], [6, 9]]
Explanation: `[1, 3]` touches `[3, 5]`, and `[6, 8]` overlaps `[7, 9]`.
Input: []
Expected Output: []
Explanation: No intervals means no occupied time.
Input: [[4, 4]]
Expected Output: [[4, 4]]
Explanation: A single interval is already merged.
Input: [[6, 8], [1, 9], [2, 4], [4, 7]]
Expected Output: [[1, 9]]
Explanation: All intervals overlap directly or indirectly, so they collapse into one interval.
Hints
- Sort the intervals by start time before trying to merge anything.
- Keep track of the last merged interval and decide whether the next interval extends it or starts a new block.
Part 2: Merge Meeting Intervals with Availability Flags
Constraints
- `0 <= len(intervals) <= 200000`
- `-10^9 <= start <= end <= 10^9`
- `is_available` is either `True` or `False`
- Touching unavailable intervals merge when `next_start == current_end`.
Examples
Input: [[5, 6, True], [1, 3, False], [2, 4, True], [4, 4, False], [6, 8, False], [8, 10, False]]
Expected Output: [[1, 3], [4, 4], [6, 10]]
Explanation: Only intervals marked `False` matter. `[6, 8]` and `[8, 10]` touch and merge.
Input: [[1, 10, True], [3, 4, False]]
Expected Output: [[3, 4]]
Explanation: The larger available interval does not remove the smaller unavailable section.
Input: [[1, 5, False], [2, 3, True], [5, 6, False]]
Expected Output: [[1, 6]]
Explanation: The unavailable intervals `[1, 5]` and `[5, 6]` touch, so they merge into `[1, 6]`.
Input: []
Expected Output: []
Explanation: No intervals means no unavailable time.
Input: [[3, 3, False]]
Expected Output: [[3, 3]]
Explanation: A single unavailable instant remains as is.
Hints
- Ask which intervals can possibly contribute to the final answer at all.
- Once you isolate the relevant intervals, the rest of the problem becomes the same as standard interval merging.
Part 3: Build a String from Binary-Tree Side Views (Both Bottom to Top)
Constraints
- `0 <= len(values) <= 100000`
- Each non-`None` entry is a string of length 1
- The input represents a valid binary tree in heap-style array form
- If the tree is empty, return an empty string
Examples
Input: (['a', 'b', 'c'],)
Expected Output: 'bac'
Explanation: Left view is a, b so bottom-to-top is ba. Right view is a, c so bottom-to-top is ca. Skip the duplicate root a and append only c, giving bac.
Input: ([],)
Expected Output: ''
Explanation: An empty array means there is no tree, so the result is an empty string.
Input: (['a', 'b', 'b'],)
Expected Output: 'bab'
Explanation: Left bottom-to-top is ba. Right bottom-to-top is ba, but only the root a is the same node. The right-side b is a different node, so it is appended.
Input: (['a', 'b', None, 'c'],)
Expected Output: 'cba'
Explanation: This is a left-skewed tree a -> b -> c. Both side views contain the same nodes, so the left bottom-to-top string cba is the full answer.
Input: (['a', 'b', 'c', 'd', None, None, 'e'],)
Expected Output: 'dbaec'
Explanation: Left view is a, b, d so bottom-to-top is dba. Right view is a, c, e so bottom-to-top is eca. Skip the duplicate root a and append ec, giving dbaec.
Input: ([None, 'a', 'b'],)
Expected Output: ''
Explanation: The root is missing, so there is no reachable tree. Nodes below it are ignored.
Hints
- A level-order traversal naturally reveals the first and last visible node at each depth.
- Store node positions, not just characters, so you can avoid reusing the same node when combining the views.
Part 4: Build a String from Binary-Tree Side Views (Left Bottom to Top, Right Top to Bottom)
Constraints
- `0 <= len(values) <= 100000`
- Each non-`None` entry is a string of length 1
- The input represents a valid binary tree in heap-style array form
- If the tree is empty, return an empty string
Examples
Input: (['a','b','c','d','e','f','g'],)
Expected Output: "dbacg"
Explanation: Left view is a, b, d, so bottom-to-top gives dba. Right view is a, c, g; skipping a because that node is already used leaves cg. Result: dbacg.
Input: ([],)
Expected Output: ""
Explanation: An empty array represents an empty tree, so the result is an empty string.
Input: (['z'],)
Expected Output: "z"
Explanation: The single root node is in both side views, but it is only included once.
Input: (['a','b',None,'c'],)
Expected Output: "cba"
Explanation: The only reachable nodes are a -> b -> c down the left side. Left view is a, b, c, so bottom-to-top is cba. The right view is the same nodes, so nothing extra is appended.
Input: (['a','b','c','d',None,None,'e'],)
Expected Output: "dbace"
Explanation: Left view is a, b, d, giving dba from bottom to top. Right view is a, c, e; skipping the shared root a leaves ce. Result: dbace.
Input: (['a','b','b','c',None,None,'c'],)
Expected Output: "cbabc"
Explanation: Left view is a, b, c, so bottom-to-top gives cba. Right view is a, b, c on different nodes at depths 1 and 2, so after skipping only the shared root, bc is appended. Equal character values do not count as duplicates if they are different nodes.
Input: ([None,'a','b'],)
Expected Output: ""
Explanation: A missing root means the tree is empty. Deeper array entries are ignored because they are not reachable from index 0.
Hints
- Use one breadth-first traversal to collect the leftmost and rightmost node at each level.
- The only difference from the previous variant is the order in which you append the right-side view.