Build a Quadtree and Analyze a Graph
Company: Uber
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates skills in spatial data structures and recursive tree construction (building a quadtree) as well as graph analysis using traversal and cycle/safety detection to identify nodes that necessarily reach terminal nodes.
Build a Quadtree from an Image
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: ([[1,1],[1,1]],)
Expected Output: {'leaf': True, 'value': 1}
Explanation: Uniform leaf.
Input: ([[1,0],[0,1]],)
Expected Output: {'leaf': False, 'children': [{'leaf': True, 'value': 1}, {'leaf': True, 'value': 0}, {'leaf': True, 'value': 0}, {'leaf': True, 'value': 1}]}
Explanation: Four leaf children.
Input: ([],)
Expected Output: None
Explanation: Empty image.
Hints
- Model object-style prompts as arrays or operation streams when needed.
- Handle empty and boundary cases before the main logic.
Eventual Safe Nodes in a Directed Graph
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: ([[1,2],[2,3],[5],[0],[5],[],[]],)
Expected Output: [2, 4, 5, 6]
Explanation: Classic safe nodes example.
Input: ([[],[0],[1]],)
Expected Output: [0, 1, 2]
Explanation: All nodes safe.
Input: ([[1],[0]],)
Expected Output: []
Explanation: Cycle has no safe nodes.
Hints
- Model object-style prompts as arrays or operation streams when needed.
- Handle empty and boundary cases before the main logic.