Skip to content

Practice Minimum Moves to Clean the Classroom

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3568
LeetCode Problem

Minimum Moves to Clean the Classroom

Problem Statement

In classroom, S is the start, L is litter, R restores energy to full capacity, X is an impassable obstacle, and . is empty space. Collecting litter empties that cell, and reset cells may be used repeatedly. Start at S with energy units. Each move to an in-bounds cardinal neighbor costs one unit. At zero energy, movement can continue only from an R cell, which restores the energy. Return the fewest moves needed to collect all litter, or -1 if impossible.

Source: Minimum Moves to Clean the Classroom on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
classroom = ["S.", "XL"], energy = 2
Output
2

# Example 2

Input
classroom = ["LS", "RL"], energy = 4
Output
3

# Example 3

Input
classroom = ["L.S", "RXL"], energy = 3
Output
-1

Constraints

1 <= m == classroom.length <= 20
1 <= n == classroom[i].length <= 20
classroom[i][j] is one of 'S', 'L', 'R', 'X', or '.'
1 <= energy <= 50
There is exactly one 'S' in the grid.
There are at most 10 'L' cells in the grid.

Related LeetCode Problems

Practice more problems similar to Minimum Moves to Clean the Classroom.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.