Find the City has two steps: Step : Compute all-pairs shortest paths using Floyd-Warshall. Step : For each city , count how many cities satisfy dist[i][j] <= threshold (excluding itself). Return the city with the minimum count.
Ties go to the larger city number. The Floyd-Warshall step is standard. The counting step is a simple loop over the distance matrix. This two-step pattern is common in graph problems.