Skip to content

Practice Alphabet Board Path

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

Medium#1138
LeetCode Problem

Alphabet Board Path

Problem Statement

Use the board rows ["abcde", "fghij", "klmno", "pqrst", "uvwxy", "z"], starting at row 0, column 0. Commands U, D, L, and R move one cell in the corresponding direction, and may only enter positions containing letters. The command ! appends the current letter to the output without moving. Return a shortest command string that produces target. Any shortest valid command string is accepted.

Source: Alphabet Board Path on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
target = "leet"
Output
"DDR!UURRR!!DDD!"

# Example 2

Input
target = "code"
Output
"RR!DDRR!UUL!R!"

Constraints

1 <= target.length <= 100
target consists only of English lowercase letters.

Related LeetCode Problems

Practice more problems similar to Alphabet Board Path.

Review your practice with PhantomCodeAI

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