Code RoomRadio mesh hops
EasyPrep Room Coding #4771

Radio mesh hops

CodingAlgorithms & data structuresEntry–Mid~15 min

A warehouse runs a radio mesh, and every device on it carries a call sign. The links are held in two parallel lists: link i joins the device named in link_a[i] to the device named in link_b[i], and a link carries traffic both ways. Distance is counted in relays. The gateway itself sits at hop 0, a device sharing a link with it sits at hop 1, and a device whose shortest route crosses two links sits at hop 2. Return the call signs of every device sitting exactly hops relays from gateway, sorted alphabetically, and an empty list when no device sits that far out. A device counts at its shortest distance only, even when a longer route also reaches it. The mesh may list the same link twice and may list a link from a device back to itself, and gateway belongs to the mesh even when it appears in no link at all.

Implement
mesh_nodes_at_hop(link_a: list[str], link_b: list[str], gateway: str, hops: int) → list[str]
Examples
in[["gate","gate","alpha","beta","beta"],["alpha","beta","delta","delta","echo"],"gate",1]out["alpha","beta"]
in[["gate","gate","alpha","beta","beta"],["alpha","beta","delta","delta","echo"],"gate",2]out["delta","echo"]
in[["gate","gate","alpha","beta","beta"],["alpha","beta","delta","delta","echo"],"gate",0]out["gate"]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 15 min
InputExpectedGot
[["gate","gate","alpha","beta","beta"],["alpha","beta","delta","delta","echo"],"gate",1]["alpha","beta"]not run yetsample
[["gate","gate","alpha","beta","beta"],["alpha","beta","delta","delta","echo"],"gate",2]["delta","echo"]not run yetsample
[["gate","gate","alpha","beta","beta"],["alpha","beta","delta","delta","echo"],"gate",0]["gate"]not run yetsample