Problem
You are given a rectangular maze represented as a 2D grid of characters. Implement and iteratively fix/extend a solver that finds a shortest path from S (start) to E (exit).
Movement is 4-directional (up/down/left/right) unless restricted by special tiles.
Base tiles
-
#
= wall (cannot enter)
-
.
= empty cell
-
S
= start
-
E
= exit
Additional tiles (introduced by later failing tests)
-
<
: from this cell, you may move
only left
on the next step
-
>
: from this cell, you may move
only right
on the next step
-
a
-
f
: keys you can pick up by entering the cell
-
A
-
F
: locks; you may enter only if you already have the corresponding key (e.g.,
a
opens
A
)
Tasks (the test suite reveals issues incrementally)
-
Fix output formatting:
implement a required
print
/render function for the maze and/or found path exactly as specified by the function contract (e.g., return a string with newline-delimited rows; if a path is found, overlay it using
*
except on
S
/
E
).
-
Fix BFS correctness:
ensure your BFS does not revisit states incorrectly (record
visited
properly).
-
Support one-way tiles:
update neighbor generation to handle
<
and
>
.
-
Support keys and locks:
update BFS to include collected keys as part of the state.
Input/Output
Implement a function with the following behavior (language-agnostic):
-
Input:
grid: string[]
(each string is a row)
-
Output:
the length of the shortest path from
S
to
E
(number of moves), or
-1
if unreachable.
-
Additionally, implement any required helper(s) such as
render(grid, path)
depending on the harness.
Constraints
-
1 <= rows, cols <= 200
-
Grid contains exactly one
S
and one
E
.
-
Keys are limited to
a
-
f
(at most 6 distinct keys).