There are N stations for relaying messages. One station sends a message to all other stations within a certain distance and each station relays the message again. Given the distance beetween all stations and distance K, tell if it's possible that all stations receive a message from a specific station.
Suggested Solution
Method: boolean canReceiveMessage(int[][] distances, int originStation, int k)
Starting from the originStation, do a BFS and only put the stations within distance k to the queue. If all stations are visited return true.
Follow up: Given the distance beetween all stations, find the minimum K to ensure all stations can receive a message from a certain station.
Suggested Solution
Find the closest station (with minDist) and farthest station (with maxDist) to the originStation. minDist <= K <=maxDist
Do a binary search between minDist and maxDist by calling canReceiveMessage.
Please let me know what you think.
YOE: 10
LOC: US
POS: L5