Graph Theory37 sections · 1633 units
Open in Course

LeetCode 1334 Find the City - Problem Statement

LeetCode 1334 walkthrough i...

The problem asks: given nn cities, edges with weights, and a distance threshold, find the city that can reach the fewest other cities within the threshold. Run Floyd-Warshall to get all-pairs distances. For each city ii, count how many cities jj have dist[i][j] <= threshold.

Return the city with the smallest count. If tied, return the city with the larger index. This problem adds a post-processing step after Floyd-Warshall.