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
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

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
BFS
State encoding
Permutation parity
A* search
Puzzle solving
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported