FastPrepSatellite Network Message Propagation

Satellite Network Message Propagation

Optiver logoOptiver● HardFULLTIMEOA
Learn

Problem statement

Maintain an undirected satellite network and simulate message propagation.

  • SATELLITE id connects a new satellite. If the ID already exists, output ErrDuplicateSatellite: id.
  • RELATION a b adds a two-way connection.
  • MESSAGE m id1 ... idm simultaneously notifies the listed satellites and runs one complete propagation.

An instruction that references nonexistent satellites outputs ErrInvalidSatellite: id once for every distinct invalid ID in left-to-right order, then makes no state change.

Propagation timing

  • Each notified satellite considers direct neighbors in increasing ID order.
  • It skips neighbors already known to be notified. It never tries to notify the satellite that notified it.
  • One forwarding attempt takes exactly 10 seconds, and one sender can have only one attempt in flight.
  • Two senders may attempt the same target concurrently. Even if another attempt finishes first or at the same time, each in-flight sender still spends its full 10 seconds.
  • After a sender finishes all required attempts, it spends 30 seconds processing and reports back.
  • Reports are ordered by time, then by smaller satellite ID.

Return every callback string in invocation order.

Function

simulateSatelliteNetwork(instructions: String[]) → String[]

Examples

Example 1

instructions = ["SATELLITE 1","SATELLITE 2","SATELLITE 3","RELATION 2 1","MESSAGE 1 2"]return = ["SatelliteReportedBack: 1","SatelliteReportedBack: 2"]

Satellite 2 forwards to 1 for 10 seconds. Both finish processing at time 40, so ID 1 reports first.

Example 2

instructions = ["SATELLITE 1","SATELLITE 2","SATELLITE 3","SATELLITE 4","SATELLITE 5","RELATION 1 3","RELATION 1 2","RELATION 2 5","RELATION 3 2","RELATION 3 4","RELATION 3 5","MESSAGE 2 1 3"]return = ["SatelliteReportedBack: 1","SatelliteReportedBack: 2","SatelliteReportedBack: 3","SatelliteReportedBack: 4","SatelliteReportedBack: 5"]

Satellites 1 and 3 start together. Concurrent attempts to 2 finish at time 10; all reports at time 50 are ordered by ID.

Constraints

  • 0 <= satelliteId < 2^16
  • 1 <= instructions.length <= 10^5
  • Each instruction has the documented valid token format.
  • Repeated relationships and duplicate IDs within one MESSAGE instruction are idempotent.

More Optiver problems

See Optiver hiring insights
public String[] simulateSatelliteNetwork(String[] instructions) {
  // write your code here
}
instructions["SATELLITE 1","SATELLITE 2","SATELLITE 3","RELATION 2 1","MESSAGE 1 2"]
expected["SatelliteReportedBack: 1", "SatelliteReportedBack: 2"]
Checking account…