#1138
Alphabet Board Path
specialist · 860 · lc medium +31 · verified · 51.8% accepted · 935 likes · top 41%
Description
Starting at position (0, 0) on an alphabet board board = ["abcde", "fghij", "klmno", "pqrst", "uvwxy", "z"], navigate to each character in target using the moves 'U' (up), 'D' (down), 'L' (left), 'R' (right), and '!' (select current character).
Return a move sequence that spells out target using the minimum number of moves.
Example 1:
Input: target = "leet"
Output: "DDR!UURRR!!DDD!"
Example 2:
Input: target = "code"
Output: "RR!DDRR!UUL!R!"
Code
1
2
3