Retryable URL Maze
Problem statement
Model a URL maze with deterministic per-endpoint response sequences. Each row in responses is [url, attempt1, attempt2, ...]. An attempt is:
503orMALFORMED: failed attempt;NEXT:a,b,...: successful response listing next URLs;CONGRATS: terminal success.
Starting at start, perform BFS with visited de-duplication. When a URL is dequeued, consume at most maxRetries + 1 attempts, stopping at its first valid NEXT or CONGRATS. An exhausted URL adds no neighbors.
Return the first BFS path from start to a URL that yields CONGRATS. Preserve NEXT order for ties. Return an empty array when no success is reachable.
Function
solveUrlMaze(start: String, responses: String[][], maxRetries: int) → String[]Examples
Example 1
start = "start"responses = [["start","503","NEXT:a,b"],["a","NEXT:c"],["b","CONGRATS"],["c","CONGRATS"]]maxRetries = 1return = ["start","b"]The start succeeds on its retry; BFS reaches b before the deeper c path.
Example 2
start = "start"responses = [["start","503","503"],["a","CONGRATS"]]maxRetries = 1return = []The start exhausts its two allowed attempts and exposes no neighbor.
Constraints
1 <= responses.length <= 10^4.- Every URL appears as the first field of at most one row.
0 <= maxRetries <= 20.