3568. Minimum Moves to Clean the Classroom Medium

@problem@discussion
#Array#Hash Table#Bit Manipulation#Breadth-First Search#Matrix



1/**
2 * [3568] Minimum Moves to Clean the Classroom
3 *
4 * <p data-end="324" data-start="147">You are given an m x n grid classroom where a student volunteer is tasked with cleaning up litter scattered around the room. Each cell in the grid is one of the following:
5 * 
6 * 	'S': Starting position of the student
7 * 	'L': Litter that must be collected (once collected, the cell becomes empty)
8 * 	'R': Reset area that restores the student's energy to full capacity, regardless of their current energy level (can be used multiple times)
9 * 	'X': Obstacle the student cannot pass through
10 * 	'.': Empty space
11 * 
12 * You are also given an integer energy, representing the student's maximum energy capacity. The student starts with this energy from the starting position 'S'.
13 * Each move to an adjacent cell (up, down, left, or right) costs 1 unit of energy. If the energy reaches 0, the student can only continue if they are on a reset area 'R', which resets the energy to its maximum capacity energy.
14 * Return the minimum number of moves required to collect all litter items, or -1 if it's impossible.
15 *  
16 * <strong class="example">Example 1:
17 * <div class="example-block">
18 * Input: <span class="example-io">classroom = ["S.", "XL"], energy = 2</span>
19 * Output: <span class="example-io">2</span>
20 * Explanation:
21 * 
22 * 	The student starts at cell <code data-end="262" data-start="254">(0, 0) with 2 units of energy.
23 * 	Since cell (1, 0) contains an obstacle 'X', the student cannot move directly downward.
24 * 	A valid sequence of moves to collect all litter is as follows:
25 * 	
26 * 		Move 1: From (0, 0) &rarr; (0, 1) with 1 unit of energy and 1 unit remaining.
27 * 		Move 2: From (0, 1) &rarr; (1, 1) to collect the litter 'L'.
28 * 	
29 * 	
30 * 	The student collects all the litter using 2 moves. Thus, the output is 2.
31 * </div>
32 * <strong class="example">Example 2:
33 * <div class="example-block">
34 * Input: <span class="example-io">classroom = ["LS", "RL"], energy = 4</span>
35 * Output: <span class="example-io">3</span>
36 * Explanation:
37 * 
38 * 	The student starts at cell <code data-end="262" data-start="254">(0, 1) with 4 units of energy.
39 * 	A valid sequence of moves to collect all litter is as follows:
40 * 	
41 * 		Move 1: From (0, 1) &rarr; (0, 0) to collect the first litter 'L' with 1 unit of energy used and 3 units remaining.
42 * 		Move 2: From (0, 0) &rarr; (1, 0) to 'R' to reset and restore energy back to 4.
43 * 		Move 3: From (1, 0) &rarr; (1, 1) to collect the second litter <code data-end="1068" data-start="1063">'L'.
44 * 	
45 * 	
46 * 	The student collects all the litter using 3 moves. Thus, the output is 3.
47 * </div>
48 * <strong class="example">Example 3:
49 * <div class="example-block">
50 * Input: <span class="example-io">classroom = ["L.S", "RXL"], energy = 3</span>
51 * Output: <span class="example-io">-1</span>
52 * Explanation:
53 * No valid path collects all 'L'.
54 * </div>
55 *  
56 * Constraints:
57 * 
58 * 	1 <= m == classroom.length <= 20
59 * 	1 <= n == classroom[i].length <= 20
60 * 	classroom[i][j] is one of 'S', 'L', 'R', 'X', or '.'
61 * 	1 <= energy <= 50
62 * 	There is exactly one 'S' in the grid.
63 * 	There are at most 10 'L' cells in the grid.
64 * 
65 */
66pub struct Solution {}
67
68// problem: https://leetcode.com/problems/minimum-moves-to-clean-the-classroom/
69// discuss: https://leetcode.com/problems/minimum-moves-to-clean-the-classroom/discuss/?currentPage=1&orderBy=most_votes&query=
70
71// submission codes start here
72
73impl Solution {
74    pub fn min_moves(classroom: Vec<String>, energy: i32) -> i32 {
75        0
76    }
77}
78
79// submission codes end
80
81#[cfg(test)]
82mod tests {
83    use super::*;
84
85    #[test]
86    fn test_3568() {
87    }
88}
89

Back
© 2026 bowen.ge All Rights Reserved.