Minimum Teleporter Repairs
Updated
Problem statement
Countries have directed teleport connections. Some countries have a broken departure teleporter, which takes one day to repair before it can be used. Find the minimum number of repair days needed to travel from source to destination; teleporting itself takes zero days.
For this exercise, assume countries are numbered 0..n-1, and each [a,b] connection permits travel from a to b. A broken teleporter belongs to its departure country, regardless of which outgoing connection is chosen. Arrival at a broken destination does not require repair. A teleporter stays repaired after its first repair; an optimal route can be chosen without repeated countries.
For this exercise, return -1 if no directed route exists and 0 if the endpoints coincide. Repeated edges and repeated entries in broken do not change the answer.
Function
minTeleporterRepairs(n: int, connections: int[][], broken: int[], source: int, destination: int) → intExamples
Example 1
n = 7connections = [[0,1],[0,2],[0,3],[1,2],[1,5],[2,3],[2,4],[2,5],[3,4],[3,6],[5,6]]broken = [5]source = 1destination = 6return = 0The path 1 -> 2 -> 3 -> 6 avoids departing from the broken teleporter at 5.
Example 2
n = 7connections = [[0,1],[0,2],[0,3],[1,2],[1,5],[2,3],[2,4],[2,5],[3,4],[3,6],[5,6]]broken = [1,5]source = 1destination = 6return = 1Every nontrivial route departs from the broken source at 1, but 1 -> 2 -> 3 -> 6 requires no additional repair.
Example 3
n = 2connections = [[0,1]]broken = []source = 1destination = 0return = -1There is no directed route from country 1 back to country 0.
Constraints
- For this exercise, assume
1 <= n <= 2000and at most10000directed connections. - Every country index, including endpoints and broken entries, lies in
[0,n-1]. broken.length <= 2000; repeated entries and self-connections are allowed.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Cheapest Flights Within K StopsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Fire Station Response BillLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Minimum Friend API CallsMercor · ONSITE INTERVIEWMercor interview questions
- Shortest Increasing Path to a TargetUber · ONSITE INTERVIEWUber interview questions
- Find and Reconstruct a Binary-Matrix PathMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Open the Lock and Return a Shortest PathZip · PHONE SCREEN · ONSITE INTERVIEWZip interview questions
- Shortest Travel Time in a Grid with Traffic LightsWaymo · PHONE SCREENWaymo interview questions
- Delivery Management SystemAkuna Capital · OAAkuna Capital interview questions
- Shortest Word Chain Between Two WordsFanatics · PHONE SCREEN
- Shortest Path from an Encoded GraphIntuit · OAIntuit interview questions