Find exit URL via BFS API calls
Company: Ramp
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: This question evaluates graph traversal and resilience when interacting with HTTP APIs, covering BFS/DFS reasoning, cycle detection to avoid infinite loops, retry handling for transient HTTP 500 responses, and timeout management for slow pages.
Constraints
- 1 <= number of paths (nodes) <= 10^4
- Each value in api is either the string "Congrats" or an object with key "next_step" (list of strings) and optional keys "fail_500" and "timeout" (non-negative integers).
- All paths and next_step entries are absolute and should start with "/"; if not, treat them as if "/" were prepended.
- The starting path "/" is present in api.
- Transient error counters are per-path and finite: a path returns HTTP 500 for its first fail_500 attempts, then times out for its next timeout attempts, then succeeds.
- Return the first exit discovered in BFS order; if none is reachable, return "".
Examples
Input:
Expected Output: ac
Hints
- Use a queue for BFS and a visited set, but only mark a node visited after a successful fetch.
- On HTTP 500 or timeout, re-enqueue the same path to retry later instead of marking it visited.
- Normalize next_step entries to absolute paths by prepending "/" when missing.