Simulate satellite message propagation with timing
Company: Optiver
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Take-home Project
Design and implement the SatelliteNetwork to process a stream of N instructions:
- SatelliteConnected(SatelliteId): add a satellite; invoke ErrDuplicateSatellite(SatelliteId) if the satellite connects more than once.
- RelationshipEstablished(SatelliteId1, SatelliteId
2): add a bidirectional link; if either SatelliteId does not exist, skip the instruction and invoke ErrInvalidSatellite(the invalid id).
- MessageReceived(M, id1..idM): treat the listed M satellites as simultaneously notified at time t = 0.
Propagation rules:
- A satellite forwards the message to each direct neighbor that has not yet been notified, one neighbor at a time, in increasing SatelliteId order; each send takes exactly 10 seconds.
- Different satellites may concurrently attempt to notify the same neighbor; each attempt still consumes 10 seconds, but as soon as any attempt completes, that neighbor is considered notified and no further attempts to it should proceed.
- A satellite never attempts to notify the satellite that notified it.
Post-notification processing:
- After all of its direct neighbors have been notified, a satellite spends 30 seconds processing the message and then reports back to Earth.
Reporting:
- Call OnSatelliteReportedBack(SatelliteId) at each satellite’s report completion time; if two reports complete at the same time, report the smaller SatelliteId first.
Task: Provide data structures and an algorithm that consume the instruction stream online and trigger OnSatelliteReportedBack calls in the correct order for any input, handling duplicates/invalid references as specified. Explain your approach and analyze time and space complexity.
Quick Answer: This question evaluates a candidate's ability to design data structures and algorithms for graph-based event-driven simulations, testing competencies in graph algorithms, concurrent timed propagation, event ordering, and online processing within the Coding & Algorithms domain.