Leetcode Problem 1263. Minimum Moves to Move a Box to Their Target Location
1263. Minimum Moves to Move a Box to Their Target Location
Leetcode Solutions
BFS within BFS Approach
Initialize a queue for the BFS process and a visited set to keep track of visited states.
Find the initial positions of the box, the storekeeper, and the target.
Enqueue the initial state (box position and storekeeper position) with a push count of 0.
While the queue is not empty:
a. Dequeue the current state.
b. If the box is at the target position, return the push count.
c. For each possible direction (up, down, left, right):
i. Calculate the new position of the storekeeper and the box if pushed.
ii. Check if the new positions are valid (not a wall and within bounds).
iii. Perform a second BFS to check if the storekeeper can reach the new position to push the box.
iv. If the storekeeper can reach and the box can be pushed, enqueue the new state with the incremented push count.