💤 Cheese Maze

This is a simpler variation of the Power-up Maze. Give that one a try after you finish this one!

Hilariously enough, Cheese Maze saved me during a contest that Lego hosted in 2023! I entered the contest with a meme team of my best friend and my mom, and was able to implement Cheese Maze in mere minutes after seeing one of the problems was very similar to it.

A mouse is running through a maze, represented by a 2D grid, shown below. A # represents a wall, and a . represents an empty tile. Each second, it can move one tile upwards, leftwards, rightwards, or downwards on an empty space, but cannot go through walls. The mouse starts on the space marked A, and wants to move to the space marked B.

Around the maze are one or more pieces of cheese marked P. The mouse has to collect every tile marked P in order to complete the maze. Whenever the mouse moves over a space marked P, it collects the cheese. The mouse must collect every piece of cheese to finish the maze.

Given a maze, return the least amount of time the mouse takes to reach point B, starting from point A.
Here is an example, along with an explanation. Press the buttons to go forward or backward a move.


{{currentMaze}}

{{currentExplanation}}

Current second: {{secondArray[index]}}



To solve this puzzle, use this link to get the large input set.
The large input set is a 23 x 23 grid.
{{response}}

Related challenges:
Maze Cleaning 💤 Power-up Maze