Fewest Slides to Solve a Two by Three Sticker Tile Puzzle
Last updated: November 29, 2026
Quick Overview
A 2 x 3 board holds tiles 1 to 5 and one blank, and a move slides an adjacent tile into the blank. Return the minimum moves to reach the arrangement [[1,2,3],[4,5,0]], or -1 if it cannot be solved.
Meta
November 29, 20260
0
0 solved
A 2 x 3 board holds tiles 1 to 5 and one blank, and a move slides an adjacent tile into the blank. Return the minimum moves to reach the arrangement [[1,2,3],[4,5,0]], or -1 if it cannot be solved.
A Meta onsite question about BFS over board states, framed as a mini game inside Messenger. The challenge is encoding the state compactly and generating moves correctly, not the search itself. Strong candidates also discuss solvability via permutation parity.
What the Interviewer Expects
- Encode boards as strings to hash states
- Precompute neighbor indices for each blank position
- Run BFS from the start until the goal state
- Explain why only 360 of 720 permutations are reachable
- Discuss A* with Manhattan distance for larger puzzles
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you check solvability without search?
- How would you scale this to a 3 x 3 or 4 x 4 puzzle?
- Return the sequence of moves.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input is a 2 x 3 list of lists containing 0..5 once each.
- A move swaps the blank with an orthogonally adjacent tile.
- Return the minimum number of moves or -1....
High-Level Design
There are only 6! = 720 arrangements, so BFS over all of them is cheap. Flatten the board to a string "123450" style key, find the blank, and swap it with each neighbor from a precomputed adjacenc...