Sliding Puzzle
A hard-tier problem at 73% community acceptance, tagged with Array, Dynamic Programming, Backtracking. Reported in interviews at Airbnb and 1 others.
Sliding Puzzle is a hard problem that appears in assessments at Airbnb and Nvidia. You're given a sliding puzzle state and need to find the minimum moves to reach the goal configuration. Most candidates see the word "puzzle" and freeze, thinking it's some obscure combinatorics problem. It's not. This is a classic shortest-path search problem disguised as a toy. The 73% acceptance rate looks forgiving until you realize it's skewed by people who've drilled BFS before. If you hit this live and don't immediately recognize the pattern, StealthCoder surfaces a working solution while the proctor watches your screen, invisible.
Companies that ask "Sliding Puzzle"
Sliding Puzzle is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop.
Get StealthCoderThe trick is recognizing this as a graph-search problem where each puzzle state is a node and each valid slide is an edge. BFS finds the shortest path from start to goal. The naive backtracking approach will time out because the state space explodes without pruning. Memoization is your guard rail: hash each state so you never explore the same configuration twice. Most candidates trap themselves trying to think mathematically about permutations when the answer is algorithmic. Array manipulation and Matrix indexing are overhead. The real work is state representation (usually flatten the 2D board into a string or tuple) and proper BFS with a visited set. Common pitfall: forgetting that the blank tile is the one that moves, not the numbered tiles. Another killer: not normalizing your state representation, so you visit the same configuration under different encodings.
Pattern tags
You know the problem.
Make sure you actually pass it.
Sliding Puzzle recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Sliding Puzzle interview FAQ
Is Sliding Puzzle actually asked at interview-stage OAs or just in practice problems?+
Airbnb and Nvidia have both reportedly asked it in their assessments. It's real. The 73% acceptance rate suggests candidates who've drilled graph search problems see it as straightforward, but candidates blind to the BFS pattern hit a wall. Expect it in harder-tier OA rounds, not early screening.
What's the actual trick to Sliding Puzzle that separates AC from TLE?+
Recognizing it as a shortest-path problem and using BFS, not backtracking. Without a visited set (memoization on state), you'll explore duplicate states exponentially. Hash your board state as a string or tuple, check before exploring, and BFS handles the rest. That distinction is the difference between passing and timing out.
How does this problem use Dynamic Programming if BFS solves it?+
It doesn't require DP directly. The DP tag likely flags that memoization (caching visited states) is essential for avoiding re-exploration. Backtracking with memoization is DP-adjacent. BFS with a visited dictionary achieves the same effect more cleanly and is the standard approach.
Do I need to optimize for board size or is any solution fast enough?+
Standard Sliding Puzzle tests assume a 4x4 board or smaller. BFS with proper state hashing handles that easily. If the board size scales beyond 5x5, the state space balloons and you'd need more aggressive pruning (A* with a heuristic like Manhattan distance), but the input will signal that.
How hard is the implementation compared to other hard graph problems?+
The code is short once you see the pattern: initialize BFS, hash your states, explore neighbors by sliding the blank tile. The hard part is recognizing the pattern in the first place and avoiding the backtracking trap. Implementation difficulty is medium once you're committed to BFS. That pattern recognition gap is where candidates usually fail.
Want the actual problem statement? View "Sliding Puzzle" on LeetCode →