This question evaluates mastery of breadth-first search, state-space modeling for grid-based traversal, and handling augmented states like keys and one-way tiles, testing competency in algorithm design and correctness within the Coding & Algorithms domain (graph algorithms).
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.
#
= wall (cannot enter)
.
= empty cell
S
= start
E
= exit
<
: 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
)
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
).
visited
properly).
<
and
>
.
Implement a function with the following behavior (language-agnostic):
grid: string[]
(each string is a row)
S
to
E
(number of moves), or
-1
if unreachable.
render(grid, path)
depending on the harness.
1 <= rows, cols <= 200
S
and one
E
.
a
-
f
(at most 6 distinct keys).