Design and Implement a Cross-System Object Tracker
WaymoSoftware Engineer · Technical ScreenLast updated
This problem tests your ability to design an efficient data structure for maintaining and merging temporal events associated with multiple system-generated IDs for the same physical object.
Problem Description
In a distributed sensor network, different systems (e.g., Radar, LiDAR, Camera) generate their own unique IDs for the same physical object. You are tasked with designing an ObjectTracker class that maintains the observation history for these objects and links multiple system IDs to a single "Global Object."
Implement the following interface:
class ObjectTracker:
def add_observation(self, system_id, object_id, timestamp, metadata):
# Records an observation for a given object_id from a specific system.
def link_systems(self, id1, id2):
# Declares that id1 and id2 represent the same physical entity.
def get_history(self, any_id):
# Returns a sorted list of all observations for the global object associated with any_id.
Requirements
- Merging: If
link_systems(A, B)is called, all observations previously associated withAandBmust now be linked to the same entity. - Consistency: Observations should be returned in chronological order. If timestamps are identical, maintain determinism (e.g., sort by
system_id). - Idempotency: Calling
link_systems(A, B)multiple times should have no side effects. - Scale: Assume a high volume of observations. Optimize for retrieving the history of an object.
Example
tracker = ObjectTracker()
tracker.add_observation("LIDAR", "L-1", 100, "loc:0,0")
tracker.add_observation("RADAR", "R-5", 105, "loc:1,1")
tracker.link_systems("L-1", "R-5")
# get_history("L-1") returns [(100, "L-1", "loc:0,0"), (105, "R-5", "loc:1,1")]
Edge Cases
- Linking IDs that have already been linked to different objects.
- Receiving observations for an ID that was linked after the observation was recorded.
- Handling empty history requests.
Hints
Hint 1
Consider using a Disjoint Set Union (DSU) or a Map-to-Parent pointer structure to track which IDs belong to the same entity.
Hint 2
Maintain a central repository of observations for each 'Root' ID identified by your union-find structure.
Hint 3
When merging two sets, ensure that you efficiently aggregate the observation lists without losing data.
Follow-up questions
- How would you modify your design if observations could arrive significantly out of chronological order?
- If the memory limit is reached, how would you persist these observations to a database while maintaining high read performance?
- How would you handle a contradiction where two systems report different metadata for the same object at the exact same timestamp?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.