Find minimum moves to solve the 15-puzzle
Company: Microsoft
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Onsite
Quick Answer: This question evaluates understanding of state-space search, heuristic reasoning, and solvability analysis for combinatorial sliding puzzles, testing algorithm design and optimization within the Coding & Algorithms domain at a practical application level with required conceptual understanding of search-space properties.
Constraints
- board is a 4x4 permutation of 0..15
Examples
Input: ([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 0]],)
Expected Output: 0
Explanation: Already solved.
Input: ([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 0, 15]],)
Expected Output: 1
Explanation: One move away.
Input: ([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 15, 14, 0]],)
Expected Output: -1
Explanation: Unsolvable parity.
Hints
- Use parity to reject impossible boards, then A* with Manhattan distance.