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: - 'S': Starting position of the student - 'L': Litter that must be collected (once collected, the cell becomes empty) - 'R': Reset area that restores the student's energy to full capacity, regardless of their current energy level (can be used multiple times) - 'X': Obstacle the student cannot pass through - '.': Empty space 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'. 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. Return the minimum number of moves required to collect all litter items, or -1 if it's impossible.
Example 1
Input: classroom = ["S.","XL"], energy = 2
Output: 2
Explanation: From S at (0,0) go right to (0,1), then down to (1,1) to collect the litter — 2 moves. The obstacle 'X' at (1,0) blocks the direct downward route.
Example 2
Input: classroom = ["LS","RL"], energy = 4
Output: 3
Explanation: Left to collect L at (0,0), down onto R to refill energy, then right onto the last L — 3 moves.
Example 3
Input: classroom = ["L.S","RXL"], energy = 3
Output: -1
Explanation: No path collects every 'L' within the energy budget, so the answer is -1.
Search the graph of situations the student can be in — not just the cell, but which litter is already collected and how much energy is left. BFS over that expanded state finds the fewest moves.
Run checks all cases above. Submit evaluates all test cases.