Find final URL by crawling until “congrats”
Company: Ramp
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Technical Screen
Overview: This question evaluates a candidate's competency in implementing robust HTTP-based crawling and traversal logic, including response parsing, retry and error handling, and termination detection.
Read the full Ramp Software Engineer interview experience this question came from
Constraints
- 0 <= len(web) <= 10^4
- 0 <= max_retries <= 10
- The total number of URLs across all `urls` lists is at most 2 * 10^4
- Each URL in a `urls` list should be processed at most once, except for internal retries caused by HTTP 503
Examples
Input: ("http://start", {"http://start": {"urls": ["http://a", "http://b"], "meta": 1}, "http://a": {"message": "dead end"}, "http://b": "congrats"}, 2)
Expected Output: "http://b"
Explanation: Start returns two next URLs. `http://a` is a dead end, and `http://b` returns `congrats`, so the answer is that final URL.
Input: ("s", {"s": {"urls": ["r"]}, "r": [{"status": 503}, {"status": 503}, "congrats"]}, 2)
Expected Output: "r"
Explanation: URL `r` returns HTTP 503 twice, then succeeds on the third attempt. With `max_retries = 2`, this is allowed.
Hints
- Model the crawl as a graph traversal: each URL is a node, and each `urls` list gives outgoing edges.
- Keep retry logic separate from your visited set: a 503 means retry the same URL, while cycle detection prevents revisiting URLs discovered through links.