Escape the Haunted Castle
Problem statement
An adventurer starts at (0, 0) in a rows × columns haunted castle. Walls are impassable, and the adventurer may move one cell up, down, left, or right.
Return the minimum number of moves needed to reach escapePoint, or -1 when no path exists.
Function
escapeCastle(rows: int, columns: int, walls: int[][], escapePoint: int[]) → intExamples
Example 1
rows = 2columns = 2walls = [[0,1]]escapePoint = [1,1]return = 2The only route moves down and then right.
Example 2
rows = 3columns = 3walls = [[1,0],[1,1],[1,2]]escapePoint = [2,2]return = -1A complete wall row separates the start from the exit.
Example 3
rows = 1columns = 1walls = []escapePoint = [0,0]return = 0The adventurer starts on the escape point.
Constraints
1 <= rows, columns <= 10.- Every wall and the escape point are distinct valid cells.
(0, 0)is not a wall.