Design a satellite propagation simulator
Problem Description
Design and implement a SatelliteNetwork class to simulate message propagation across an undirected graph of satellites. The class must provide the following methods:
Core Methods
satellite_connected(satellite_id): Registers a new satellite with the givensatellite_id. If a satellite with this ID already exists, anErrDuplicateSatelliteId(satellite_id)error should be raised.relationship_established(satellite_id1, satellite_id2): Establishes a bidirectional communication link betweensatellite_id1andsatellite_id2. If eithersatellite_id1orsatellite_id2does not exist, anErrInvalidSatelliteId(offending_id)error should be raised, whereoffending_idis the invalid ID.message_received(satellite_ids): Simulates Earth sending the same message simultaneously at timet=0to all satellites listed insatellite_ids. If any ID in the list does not exist, anErrInvalidSatelliteId(offending_id)error should be raised.
Message Propagation Rules
- First Reception: When a satellite first receives a message at time
t, it attempts to forward it to each of its directly connected neighbors that have not yet received this specific message. - Forwarding Time: Each such neighbor receives the message at time
t + 10s. Forwarding takes 10 seconds per sender. - Ignoring Subsequent Receptions: A satellite processes only its first reception of a given message and ignores any subsequent receptions of the same message.
- Reporting Eligibility: A satellite becomes eligible to report back to Earth once all of its direct neighbors have received the message (from any sender).
- Report Delivery Time: The satellite's report is delivered at the earliest time this eligibility condition becomes true, plus an additional 30 seconds.
- Deterministic Report Order: When multiple reports are delivered at the exact same time, they must be processed in increasing
SatelliteIdorder.
Side Effects and Output
- For each satellite report, the
OnSatelliteReportedBack(satelliteId)callback must be invoked. - These callbacks must be invoked in the exact chronological order of report delivery for that specific message.
- The methods themselves should not return or print anything else.
Assumptions and Constraints
- Satellite IDs are integers.
- Multiple calls to
message_receivedshould be treated as independent simulation runs; the state of the network (satellites and links) persists, but message propagation state resets for each new message. - The design must handle a large number of
Nsatellites andMlinks efficiently. - All operations, especially report ordering, must ensure deterministic behavior.
- Candidates should provide code or pseudocode and analyze the time and space complexity of their solution.
AI interview prep
Core dilemma
The central engineering conflict is designing an efficient, event-driven simulation system for message propagation across a dynamic graph, ensuring strict chronological and deterministic ordering of outputs (especially for simultaneous events) while handling complex, time-dependent state transitions for each satellite and message.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Design a satellite propagation simulator
Problem Description
Design and implement a SatelliteNetwork class to simulate message propagation across an undirected graph of satellites. The class must provide the following methods:
Core Methods
satellite_connected(satellite_id): Registers a new satellite with the givensatellite_id. If a satellite with this ID already exists, anErrDuplicateSatelliteId(satellite_id)error should be raised.relationship_established(satellite_id1, satellite_id2): Establishes a bidirectional communication link betweensatellite_id1andsatellite_id2. If eithersatellite_id1orsatellite_id2does not exist, anErrInvalidSatelliteId(offending_id)error should be raised, whereoffending_idis the invalid ID.message_received(satellite_ids): Simulates Earth sending the same message simultaneously at timet=0to all satellites listed insatellite_ids. If any ID in the list does not exist, anErrInvalidSatelliteId(offending_id)error should be raised.
Message Propagation Rules
- First Reception: When a satellite first receives a message at time
t, it attempts to forward it to each of its directly connected neighbors that have not yet received this specific message. - Forwarding Time: Each such neighbor receives the message at time
t + 10s. Forwarding takes 10 seconds per sender. - Ignoring Subsequent Receptions: A satellite processes only its first reception of a given message and ignores any subsequent receptions of the same message.
- Reporting Eligibility: A satellite becomes eligible to report back to Earth once all of its direct neighbors have received the message (from any sender).
- Report Delivery Time: The satellite's report is delivered at the earliest time this eligibility condition becomes true, plus an additional 30 seconds.
- Deterministic Report Order: When multiple reports are delivered at the exact same time, they must be processed in increasing
SatelliteIdorder.
Side Effects and Output
- For each satellite report, the
OnSatelliteReportedBack(satelliteId)callback must be invoked. - These callbacks must be invoked in the exact chronological order of report delivery for that specific message.
- The methods themselves should not return or print anything else.
Assumptions and Constraints
- Satellite IDs are integers.
- Multiple calls to
message_receivedshould be treated as independent simulation runs; the state of the network (satellites and links) persists, but message propagation state resets for each new message. - The design must handle a large number of
Nsatellites andMlinks efficiently. - All operations, especially report ordering, must ensure deterministic behavior.
- Candidates should provide code or pseudocode and analyze the time and space complexity of their solution.