Graph Theory37 sections · 1633 units
Open in Course

LeetCode 1334 Find the City - Breaking Down the Problem

(Two-step approach)

Find the City has two steps: Step 11: Compute all-pairs shortest paths using Floyd-Warshall. Step 22: For each city ii, count how many cities jj satisfy dist[i][j] <= threshold (excluding ii 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.