Skip to content

Commit b14d51f

Browse files
committed
Create README - LeetHub
1 parent 84cc62a commit b14d51f

File tree

1 file changed

+47
-0
lines changed
  • 1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance

1 file changed

+47
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<h2><a href="https://leetcode.com/problems/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance">1334. Find the City With the Smallest Number of Neighbors at a Threshold Distance</a></h2><h3>Medium</h3><hr><p>There are <code>n</code> cities numbered from <code>0</code> to <code>n-1</code>. Given the array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> represents a bidirectional and weighted edge between cities <code>from<sub>i</sub></code> and <code>to<sub>i</sub></code>, and given the integer <code>distanceThreshold</code>.</p>
2+
3+
<p>Return the city with the smallest number of cities that are reachable through some path and whose distance is <strong>at most</strong> <code>distanceThreshold</code>, If there are multiple such cities, return the city with the greatest number.</p>
4+
5+
<p>Notice that the distance of a path connecting cities <em><strong>i</strong></em> and <em><strong>j</strong></em> is equal to the sum of the edges&#39; weights along that path.</p>
6+
7+
<p>&nbsp;</p>
8+
<p><strong class="example">Example 1:</strong></p>
9+
<img alt="" src="https://assets.leetcode.com/uploads/2020/01/16/find_the_city_01.png" style="width: 300px; height: 225px;" />
10+
<pre>
11+
<strong>Input:</strong> n = 4, edges = [[0,1,3],[1,2,1],[1,3,4],[2,3,1]], distanceThreshold = 4
12+
<strong>Output:</strong> 3
13+
<strong>Explanation: </strong>The figure above describes the graph.&nbsp;
14+
The neighboring cities at a distanceThreshold = 4 for each city are:
15+
City 0 -&gt; [City 1, City 2]&nbsp;
16+
City 1 -&gt; [City 0, City 2, City 3]&nbsp;
17+
City 2 -&gt; [City 0, City 1, City 3]&nbsp;
18+
City 3 -&gt; [City 1, City 2]&nbsp;
19+
Cities 0 and 3 have 2 neighboring cities at a distanceThreshold = 4, but we have to return city 3 since it has the greatest number.
20+
</pre>
21+
22+
<p><strong class="example">Example 2:</strong></p>
23+
<img alt="" src="https://assets.leetcode.com/uploads/2020/01/16/find_the_city_02.png" style="width: 300px; height: 225px;" />
24+
<pre>
25+
<strong>Input:</strong> n = 5, edges = [[0,1,2],[0,4,8],[1,2,3],[1,4,2],[2,3,1],[3,4,1]], distanceThreshold = 2
26+
<strong>Output:</strong> 0
27+
<strong>Explanation: </strong>The figure above describes the graph.&nbsp;
28+
The neighboring cities at a distanceThreshold = 2 for each city are:
29+
City 0 -&gt; [City 1]&nbsp;
30+
City 1 -&gt; [City 0, City 4]&nbsp;
31+
City 2 -&gt; [City 3, City 4]&nbsp;
32+
City 3 -&gt; [City 2, City 4]
33+
City 4 -&gt; [City 1, City 2, City 3]&nbsp;
34+
The city 0 has 1 neighboring city at a distanceThreshold = 2.
35+
</pre>
36+
37+
<p>&nbsp;</p>
38+
<p><strong>Constraints:</strong></p>
39+
40+
<ul>
41+
<li><code>2 &lt;= n &lt;= 100</code></li>
42+
<li><code>1 &lt;= edges.length &lt;= n * (n - 1) / 2</code></li>
43+
<li><code>edges[i].length == 3</code></li>
44+
<li><code>0 &lt;= from<sub>i</sub> &lt; to<sub>i</sub> &lt; n</code></li>
45+
<li><code>1 &lt;= weight<sub>i</sub>,&nbsp;distanceThreshold &lt;= 10^4</code></li>
46+
<li>All pairs <code>(from<sub>i</sub>, to<sub>i</sub>)</code> are distinct.</li>
47+
</ul>

0 commit comments

Comments
 (0)