1263. Minimum Moves to Move a Box to Their Target Location Hard
1/**
2 * [1263] Minimum Moves to Move a Box to Their Target Location
3 *
4 * A storekeeper is a game in which the player pushes boxes around in a warehouse trying to get them to target locations.
5 * The game is represented by an m x n grid of characters grid where each element is a wall, floor, or box.
6 * Your task is to move the box 'B' to the target position 'T' under the following rules:
7 *
8 * The character 'S' represents the player. The player can move up, down, left, right in grid if it is a floor (empty cell).
9 * The character '.' represents the floor which means a free cell to walk.
10 * The character '#' represents the wall which means an obstacle (impossible to walk there).
11 * There is only one box 'B' and one target cell 'T' in the grid.
12 * The box can be moved to an adjacent free cell by standing next to the box and then moving in the direction of the box. This is a push.
13 * The player cannot walk through the box.
14 *
15 * Return the minimum number of pushes to move the box to the target. If there is no way to reach the target, return -1.
16 *
17 * Example 1:
18 * <img alt="" src="https://assets.leetcode.com/uploads/2019/11/06/sample_1_1620.png" style="width: 500px; height: 335px;" />
19 * Input: grid = [["#","#","#","#","#","#"],
20 * ["#","T","#","#","#","#"],
21 * ["#",".",".","B",".","#"],
22 * ["#",".","#","#",".","#"],
23 * ["#",".",".",".","S","#"],
24 * ["#","#","#","#","#","#"]]
25 * Output: 3
26 * Explanation: We return only the number of times the box is pushed.
27 * Example 2:
28 *
29 * Input: grid = [["#","#","#","#","#","#"],
30 * ["#","T","#","#","#","#"],
31 * ["#",".",".","B",".","#"],
32 * ["#","#","#","#",".","#"],
33 * ["#",".",".",".","S","#"],
34 * ["#","#","#","#","#","#"]]
35 * Output: -1
36 *
37 * Example 3:
38 *
39 * Input: grid = [["#","#","#","#","#","#"],
40 * ["#","T",".",".","#","#"],
41 * ["#",".","#","B",".","#"],
42 * ["#",".",".",".",".","#"],
43 * ["#",".",".",".","S","#"],
44 * ["#","#","#","#","#","#"]]
45 * Output: 5
46 * Explanation: push the box down, left, left, up and up.
47 *
48 *
49 * Constraints:
50 *
51 * m == grid.length
52 * n == grid[i].length
53 * 1 <= m, n <= 20
54 * grid contains only characters '.', '#', 'S', 'T', or 'B'.
55 * There is only one character 'S', 'B', and 'T' in the grid.
56 *
57 */
58pub struct Solution {}
59
60// problem: https://leetcode.com/problems/minimum-moves-to-move-a-box-to-their-target-location/
61// discuss: https://leetcode.com/problems/minimum-moves-to-move-a-box-to-their-target-location/discuss/?currentPage=1&orderBy=most_votes&query=
62
63// submission codes start here
64
65impl Solution {
66 pub fn min_push_box(grid: Vec<Vec<char>>) -> i32 {
67 0
68 }
69}
70
71// submission codes end
72
73#[cfg(test)]
74mod tests {
75 use super::*;
76
77 #[test]
78 fn test_1263() {
79 }
80}
81
Back
© 2025 bowen.ge All Rights Reserved.