Best Telescope Site
Updated
Problem 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 Online Assessment questions
- 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
- Binary Search Tree IteratorOA · Seen Nov 2023
- Binary Tree Level Order TraversalOA · Seen Nov 2023
Similar questions at other companies
- Sum Dynamic Weighted Tree DistancesJuspay · OA
- Minimum Fuel Cost Between CitiesMicrosoft · OAMicrosoft interview questions
- Drone Delivery with Battery Swap StationsCisco · OACisco interview questions
- Optimal TransferSuperhuman · OASuperhuman interview questions
- Minimum Travel Time With Periodic Fast RoadsAdobe · OAAdobe interview questions
- Find the PathLinkedIn · OALinkedIn interview questions
- Energy CrisisRubrik · OARubrik interview questions
- Compute Number of LocationsMoney Forward · OA
- Cheapest Flight with Its PathAirbnb · OA · ONSITE INTERVIEWAirbnb interview questions
- Traveling the GraphsOptiver · OAOptiver interview questions