Gamified challenge · 0-1 BFS
Each row of maze is a string: # is a wall, . is floor, S is where you start and E is the exit. A lowercase letter is a teleporter pad; it is floor too, and every pad with the same letter is linked.
Walking up, down, left or right onto any non-wall cell costs 1. Standing on a pad, you may teleport to any other pad with the same letter for 0. Write cheapestRoute(maze) that returns the cheapest total cost from S to E, or -1 if the exit can't be reached.
Example: in ["S.a#...", ".###.#.", "...#.aE"] walk two steps to the a pad, teleport to the other a, and step onto E: cost 3.
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google