Skip to content

Practice Grid Teleportation Traversal

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3552
LeetCode Problem

Grid Teleportation Traversal

Problem Statement

In matrix, a dot is an empty cell, a hash is an obstacle, and an uppercase letter marks a portal. Start at (0, 0) and reach the bottom-right cell using one move for each orthogonal step into a non-obstacle cell. From a portal cell, you may teleport for zero moves to another cell with the same letter, using each letter’s teleportation at most once in the journey. Return the minimum moves, or -1 if unreachable.

Source: Grid Teleportation Traversal on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
matrix = ["A..",".A.","..."]
Output
2

# Example 2

Input
matrix = [".#...",".#.#.",".#.#.","...#."]
Output
13

Constraints

1 <= m == matrix.length <= 10^3
1 <= n == matrix[i].length <= 10^3
matrix[i][j] is either '#', '.', or an uppercase English letter.
matrix[0][0] is not an obstacle.

Related LeetCode Problems

Practice more problems similar to Grid Teleportation Traversal.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.