Problem · Graph
Best Telescope Site
Learn this problemProblem statement
There are cityNodes cities numbered from 1 to cityNodes. The arrays cityFrom, cityTo, and cityWeight describe weighted bidirectional edges of a connected graph.
For each city, count the other cities whose shortest-path distance is at most distanceThreshold. Return the city with the smallest count. If several cities tie, return the highest city number.
Function
bestTelescopeSite(cityNodes: int, cityFrom: int[], cityTo: int[], cityWeight: int[], distanceThreshold: int) → intExamples
Example 1
cityNodes = 3cityFrom = [1,2]cityTo = [2,3]cityWeight = [3,1]distanceThreshold = 3return = 3Cities 1 and 3 each reach one other city within the threshold; the higher-numbered city 3 wins the tie.
Constraints
2 <= cityNodes <= 1001 <= cityFrom.length <= 100001 <= cityWeight[i], distanceThreshold <= 10^9- The graph is connected.
More Atlassian problems
- Planning ProductionOA · Seen Feb 2025
- K-Means ClusteringOA · Seen Feb 2025
- Minimum Sorted Erasure OperationsOA · Seen Jun 2024
- Count Analogous ArraysOA · Seen Mar 2024
- Get Maximum ScoreOA · Seen Mar 2024
- Better Compression 🦀OA · Seen Mar 2024
- Romanizer 🐡OA · Seen Mar 2024
- Flower Bouquets 💐OA · Seen Mar 2024