City With the Fewest Reachable Neighbors (Floyd–Warshall)

Medium · Graphs · about 25 minutes

Asked at Uber, Google, DoorDash, Grab, Swiggy.

n cities are joined by two-way roads edges[i] = [from, to, weight]. For each city, count the other cities reachable from it by some route whose total weight is no more than distanceThreshold. Return the city with the lowest count; if several cities share it, return the one with the highest index.

Related guides