Practice Minimum Moves to Reach Target with Rotations
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Minimum Moves to Reach Target with Rotations
Problem Statement
A two-cell snake starts horizontally at (0, 0) and (0, 1) in an n by n grid, where 0 is empty and 1 is blocked. Its target is the horizontal pair (n - 1, n - 2) and (n - 1, n - 1). One move may shift it one cell right or down without changing orientation, provided every destination cell is empty. A horizontal snake at (r, c), (r, c + 1) may rotate clockwise to (r, c), (r + 1, c) if both cells directly below it are empty. A vertical snake may make the reverse rotation if both cells directly to its right are empty. Every required cell must be inside the grid. Return the fewest moves, or -1 if unreachable.
Source: Minimum Moves to Reach Target with Rotations on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
grid = [[0,0,0,0,0,1], [1,1,0,0,1,0], [0,0,0,0,1,1], [0,0,1,0,1,0], [0,1,1,0,0,0], [0,1,1,0,0,0]]
11
# Example 2
grid = [[0,0,1,1,1,1], [0,0,0,0,1,1], [1,1,0,0,0,1], [1,1,1,0,0,1], [1,1,1,0,0,1], [1,1,1,0,0,0]]
9
Constraints
Related LeetCode Problems
Practice more problems similar to Minimum Moves to Reach Target with Rotations.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.