Tap here to switch tabs
Problem
Submissions

Problem: Sliding Puzzle

med
30 min
Try to solve the Sliding Puzzle problem.

Statement

You are given a 2×32 \times 3 integer grid board representing a sliding puzzle. The grid contains the numbers from 00 to 55, where 0 denotes the empty space. In one move, you may swap 0 with one of its adjacent cells that shares an edge with it.

The puzzle is considered solved when board becomes [[1,2,3],[4,5,0]]. Return the minimum number of moves required to reach the solved configuration. If it is impossible, return −1-1.

Constraints:

  • board.length == 2

  • board[i].length == 3

  • 0≤0 \leq board[i][j] ≤5\leq 5

  • Each value board[i][j] is unique.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Sliding Puzzle

med
30 min
Try to solve the Sliding Puzzle problem.

Statement

You are given a 2×32 \times 3 integer grid board representing a sliding puzzle. The grid contains the numbers from 00 to 55, where 0 denotes the empty space. In one move, you may swap 0 with one of its adjacent cells that shares an edge with it.

The puzzle is considered solved when board becomes [[1,2,3],[4,5,0]]. Return the minimum number of moves required to reach the solved configuration. If it is impossible, return −1-1.

Constraints:

  • board.length == 2

  • board[i].length == 3

  • 0≤0 \leq board[i][j] ≤5\leq 5

  • Each value board[i][j] is unique.