Reported October 2024
Personabreadth first search

Escape the Haunted Castle

Reported by candidates from Persona's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Persona OA. Under 2s to a working solution.
Founder's read

Persona reportedly asked "Escape the Haunted Castle" in October 2024, and the whole thing hinges on a queue. It's a shortest path on a small grid with walls, and BFS is the answer. If you've got an OA coming and you see a grid, a start, an exit and a "minimum moves" ask, this is the shape. The grid tops out at 10 by 10, so nothing needs to be clever. The risk is sloppy edge cases, not hard algorithms. StealthCoder sits invisibly on your screen as a safety net if your mind goes blank mid-assessment, but you can likely write this one cold.

The problem

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[]) → int

Examples
Example 1
rows = 2
columns = 2
walls = [[0,1]]
escapePoint = [1,1]
return = 2
The only route moves down and then right.
Example 2
rows = 3
columns = 3
walls = [[1,0],[1,1],[1,2]]
escapePoint = [2,2]
return = -1
A complete wall row separates the start from the exit.
Example 3
rows = 1
columns = 1
walls = []
escapePoint = [0,0]
return = 0
The 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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Use breadth-first search from (0, 0) with a queue. Store each cell with its distance, or process the queue level by level. Put walls in a set or mark them in a boolean grid up front. Mark cells visited when you push them, not when you pop them, or you'll enqueue duplicates and slow things down. Pop a cell, and if it equals escapePoint, return its distance. Otherwise try the four neighbors, skip anything out of bounds, walled, or visited. If the queue empties, return -1. Check Example 3 first: start equals escape, so the answer is 0 before any loop runs. Don't reach for DFS, since it finds a path but not the shortest one. If you blank during the live OA, StealthCoder is the hedge that reads the problem and hands you the BFS skeleton. The walls arrive as [row, col] pairs, so mind the order.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Escape the Haunted Castle cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as shortest path in binary matrix. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Persona's OA.

Persona reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Escape the Haunted Castle FAQ

What's the trick to Escape the Haunted Castle?+

Run BFS from (0, 0). Every move costs one, so BFS reaches each cell first by its shortest path. Track distance with each queued cell, mark visited on push, and return -1 if the queue empties without hitting escapePoint.

How hard is this problem really?+

Easy to medium. The constraints cap the grid at 10 by 10, so performance isn't the issue. Most failures come from skipping visited checks, mixing up row and column order, or forgetting the start equals escape case.

Why not use DFS?+

DFS finds a path, not necessarily the shortest one. You'd need to explore every path and keep the minimum, which is messier and slower. BFS gives the minimum on the first arrival at the target in an unweighted grid.

What edge cases should I test?+

Test a 1 by 1 grid where the start is the escape, which returns 0. Test a fully walled-off row, which returns -1. Test an escape point surrounded by walls. Also test a single-row or single-column grid with no walls.

How do I prepare for this in 48 hours?+

Write grid BFS from scratch two or three times until the direction array, bounds check, and visited set feel automatic. Then try a variant with a different start or extra obstacles. That covers most of what this question tests.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Persona.

OA at Persona?
Invisible during screen share
Get it