Practice Minimum Moves to Move a Box to Their Target Location
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 Move a Box to Their Target Location
Problem Statement
In grid, S is the player, B the single box, T the single target, . an empty floor cell, and # a wall. The player may walk up, down, left, or right through free cells, but not through walls or the box. To push the box one cell, the player must stand next to it on the opposite side and move toward it; the destination beyond the box must be free. Return the minimum number of pushes needed to put B on T, or -1 if impossible. Walking without pushing does not add to the push count.
Source: Minimum Moves to Move a Box to Their Target Location on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
grid = [["#","#","#","#","#","#"], ["#","T","#","#","#","#"], ["#",".",".","B",".","#"], ["#",".","#","#",".","#"], ["#",".",".",".","S","#"], ["#","#","#","#","#","#"]]
3
# Example 2
grid = [["#","#","#","#","#","#"], ["#","T","#","#","#","#"], ["#",".",".","B",".","#"], ["#","#","#","#",".","#"], ["#",".",".",".","S","#"], ["#","#","#","#","#","#"]]
-1
# Example 3
grid = [["#","#","#","#","#","#"], ["#","T",".",".","#","#"], ["#",".","#","B",".","#"], ["#",".",".",".",".","#"], ["#",".",".",".","S","#"], ["#","#","#","#","#","#"]]
5
Constraints
Related LeetCode Problems
Practice more problems similar to Minimum Moves to Move a Box to Their Target Location.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.