← 返回 meta 的题目列表Progressive Maze Solver (Fix Tests → BFS Shortest Path → Movement Constraints → Keys & Doors)
类型:online_judge
Problem: Progressive Maze Solver (AI-enabled coding / given codebase)
You are given an existing maze-solver codebase with unit tests. The maze is a 2D grid:
S: start
E: exit/target
#: wall (blocked)
.: empty cell (walkable)
Possibly also:
a-f: keys
A-F: doors (requires the corresponding lowercase key)
You can move to adjacent cells (typically 4-directional; follow the provided code/tests). Each move costs 1.
Part 1: Fix failing test cases
Without changing the intended behavior, fix bugs in the current implementation so that all provided unit tests pass.
Part 2: BFS shortest path
Implement/complete a function that returns the shortest number of steps (or the shortest path, per tests) from S to E using BFS. Return -1/None if unreachable (per test contract).
Part 3: Add movement-direction constraints
Update move() / neighbors() to enforce additional movement constraints (as specified during the interview). Add necessary if checks to disallow invalid moves, while still computing the shortest feasible result.
Part 4: Add keys & doors
Extend the maze with keys and doors:
Collect a key when you step on it.
You may pass through a door A only if you already have key a.
Extend BFS state to include the set of collected keys (commonly as a bitmask) and return the shortest steps from S to E.
Constraints (typical; infer from tests)
Grid size: R x C (e.g., up to 100x100)
Number of keys: K <= 6 (common for bitmask)
Example (illustrative)
Grid:
S..
##.
..E
Output:
4
Example
Input
3 3
S..
##.
..E
Output
4