AlgoMaster Logo

Maze Solver: Solution Walkthrough

High Priority16 min readUpdated November 11, 2026

Maze Solver is a small library for working with text-based mazes. It parses a maze, uses breadth-first search (BFS) to find the shortest path from the start to an exit, and draws that path onto the maze.

The round is divided into four phases over 60 minutes:

  • Phase 0: Understand the existing code.
  • Phase 1: Fix a crash that occurs when open cells touch the right edge of the maze.
  • Phase 2: Add support for one-way gates and update how paths are drawn.
  • Phase 3: Find the nearest exit from 30,000 starting points on an 800 x 800 maze within a time limit.

The BFS algorithm itself isn't the difficult part. The grid and graph search lesson in module 9 covers it in general.

What makes this round hard is three narrow decisions: which cell a gate rule applies to, what a backwards search means once some moves are one-way, and how a search starting from all exits at once breaks ties between exits.

Each decision has a tempting but incorrect answer that still passes every visible test. The hidden tests are written to catch exactly these mistakes.

Premium Content

Subscribe to unlock full access to this content and more premium articles.