Skip to content

Instantly share code, notes, and snippets.

@yigitozkavci
Last active November 4, 2019 13:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yigitozkavci/029efff939e16d394d9d4a99baafd483 to your computer and use it in GitHub Desktop.
Save yigitozkavci/029efff939e16d394d9d4a99baafd483 to your computer and use it in GitHub Desktop.
Broadcaster Interview Question

Broadcaster

Create a binary that, when executed, links itself to other broadcaster binaries that are running. This binary is able to receive instructions to display and broadcast a message to other broadcasters it's linked to.

The resulting graph of linked broadcasters should always constitute a spanning tree, in other words, all of them should be connected and there shouldn't be any redundant edges.

Example

$ broadcaster --port 8000
Started listening for instructions on :8000.
$ broadcaster --port 8001 --link 8000
Linked to broadcaster at :8000.
Started listening for instructions on :8001.
$ broadcaster --port 8002 --link 8000
Linked to broadcaster at :8000.
Started listening for instructions on :8002.
$ broadcaster --port 8003 --link 8002
Linked to broadcaster at :8002.
Started listening for instructions on :8003.

Visual

Following diagram visualizes the case when "8082" receives a message instruction. A blue node means that it's printing a message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment