Katkat

Find an Exit in a URL Maze

RampSoftware Engineer · Technical Screen

Last updated

This question evaluates graph traversal and state-management skills, emphasizing handling cycles, HTTP error conditions, retry logic, and propagation of authorization tokens in a networked client.

You are given a starting URL for a web-based maze. Each URL represents one room in the maze. Your task is to write a program that discovers whether there is a path from the starting room to an exit room.

Assume you have a helper function or HTTP client that can request a room URL. A successful response has status code 200 and returns JSON in this shape:

{
 "is_exit": false,
 "neighbors": ["https://maze.example/room/2", "https://maze.example/room/7"]
}

A room is an exit if is_exit is true. The maze may contain cycles, so your solution must not revisit the same URL indefinitely.

Implement:

def find_exit(start_url: str) -> str | None:
 pass

Return the URL of any exit room reachable from start_url, or None if no exit is reachable.

Follow-up: The maze service is unreliable and protected by per-room access keys.

Additional behavior:

  1. A request may return 503 Service Unavailable. In that case, retry the same URL a limited number of times before treating it as temporarily unreachable.
  2. A request may return 401 Unauthorized. Some successful room responses may include a key, for example:
{
 "is_exit": false,
 "neighbors": ["https://maze.example/room/9"],
 "key": "abc123"
}

When a key is returned, capture it and include it in future requests using a header such as:

Authorization: Bearer abc123

Update your implementation so it can still find an exit while handling cycles, retries, 503 responses, 401 responses, and authorization keys.