← Questions

Sliding puzzle on a 2 by 3 board

0
AirbnbCodingLast asked Apr 2026

A 2 by 3 board holds tiles 1 to 5 and one empty cell. A move slides a tile next to the empty cell into it. Return the fewest moves to reach the solved board, or -1 if it cannot be solved. Encode each board as a string and run a breadth-first search over states.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding