Dynamic Broadcast Times
Updated
Problem statement
A network contains n cities numbered from 0 to n - 1. Each directed connection has a positive ping time. The row edges[i] = [from, to, weight] defines edge i; edge indices remain fixed throughout the operation sequence.
Process the operations in order:
[0, edgeIndex, newWeight]replaces the weight of the existing edge atedgeIndexwithnewWeight.[1, source]asks for the fastest broadcast time fromsourceto every city using the current weights.
For every query, append an array of length n in city-index order. The distance to source is 0, and the distance to an unreachable city is -1. Return the query-result arrays in operation order.
Function
processBroadcastOperations(n: int, edges: long[][], operations: long[][]) → long[][]Examples
Example 1
n = 4edges = [[0,1,5],[0,2,20],[1,2,4],[2,3,3]]operations = [[1,0],[0,1,6],[1,0],[0,0,15],[1,0]]return = [[0,5,9,12],[0,5,6,9],[0,15,6,9]]The first query reaches city 2 through city 1. Lowering edge 1 makes the direct route faster. Raising edge 0 later changes city 1 without affecting the direct route to city 2.
Example 2
n = 3edges = [[0,1,2]]operations = [[1,0],[1,2],[0,0,7],[1,0]]return = [[0,2,-1],[-1,-1,0],[0,7,-1]]City 2 cannot reach either other city. Updating the only edge changes the distance from city 0 to city 1, while city 2 remains unreachable.
Example 3
n = 5edges = [[0,1,10],[0,2,2],[2,1,3],[1,3,2],[2,3,20],[3,4,1]]operations = [[1,0],[0,4,1],[1,0],[1,2]]return = [[0,5,2,7,8],[0,5,2,3,4],[-1,3,0,1,2]]After edge 4 decreases to weight 1, the route from city 0 through city 2 reaches cities 3 and 4 sooner. The final query uses city 2 as its source.
Constraints
1 <= n <= 500.0 <= edges.length <= 5000.- Every edge is
[from, to, weight], where both endpoints are valid city indices and1 <= weight <= 10^9. 1 <= operations.length <= 5000, and at least one operation is a query.- Every update is
[0, edgeIndex, newWeight], whereedgeIndexnames an existing edge and1 <= newWeight <= 10^9. - Every query is
[1, source], where0 <= source < n. - Every shortest-path distance fits a signed 64-bit integer.
More Netflix interview questions
- Timed Cache with Sidecar CleanupPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Repeated Titles in Viewing HistoryPHONE SCREEN · Seen Sep 2026
- Capacity-Limited Timed CachePHONE SCREEN · Seen Sep 2026
- Custom Record and Free-Form Field ParserPHONE SCREEN · Seen Sep 2026
- Count String Pairs With Disjoint CharactersPHONE SCREEN · Seen Aug 2026
- Deduplicate Homepage Content Across RowsPHONE SCREEN · Seen Aug 2026
- Longest Consecutive Identical Character RunPHONE SCREEN · Seen Aug 2026
- Longest Substring Without Repeating CharactersPHONE SCREEN · Seen Aug 2026
- Topological Sort for Ads TasksPHONE SCREEN · Seen Jun 2026
- Score-Rotating Movie PlaylistONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Safest Mouse Path Away from a CatGoogle · PHONE SCREENGoogle interview questions
- Shortest Path Around Moving ParadesZip · PHONE SCREENZip interview questions
- Concurrent Web Crawler SimulationOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Shortest Travel Time in a Grid with Traffic LightsWaymo · PHONE SCREENWaymo interview questions
- Cheapest Flights Within K StopsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Shortest Paths in a Nonnegative Directed GraphNation with NaMo · PHONE SCREEN
- Dijkstra Shortest Paths in a Weighted Undirected GraphGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
- Shortest Path with Directional Move CostsThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
- Shortest-Path Distances with DijkstraApple · PHONE SCREENApple interview questions
- Fastest Flight Route Between AirportsAirbnb · PHONE SCREENAirbnb interview questions