Your question is Graph Traversal Coding Problem. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
TikTok Trust and Safety services route security events through directed processing nodes. Each connection has a positive latency, and an incident may use at most one emergency firewall bypass that reduces the latency of one connection to floor(latency / 2).
Given the graph, source, and destination, return the minimum possible total latency. The bypass may be unused, and each connection can be traversed at most as part of the selected route. Return -1 if the destination is unreachable.
Implement shortest_route_with_bypass(n, edges, source, destination).
n is an integer number of nodes labeled 0 through n - 1.edges is a list of directed triples [u, v, latency].source and destination are integer node labels.-1 when no route exists.Treat each node as having two states: the bypass is unused or already used. A route cannot use the bypass more than once.
def shortest_route_with_bypass(n, edges, source, destination):