PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Microsoft

Find minimum moves to solve the 15-puzzle

Last updated: Mar 29, 2026

Quick Overview

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.

  • hard
  • Microsoft
  • Coding & Algorithms
  • Software Engineer

Find minimum moves to solve the 15-puzzle

Company: Microsoft

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Onsite

## Problem Given a 4×4 sliding puzzle (the classic **15-puzzle**), compute the **minimum number of moves** required to reach the solved state, or return `-1` if it is impossible. - The board contains numbers `1..15` and a blank represented by `0`. - A move consists of swapping `0` with one of its 4-directional neighbors (up/down/left/right). ### Input A 4×4 integer matrix `board`. ### Output An integer `minMoves`: - the minimum number of moves to reach the target state, or - `-1` if the target state is unreachable. ### Target state ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 ``` ### Constraints/Notes - You must handle unsolvable configurations. - Aim for an approach that can finish in reasonable time for typical interview test cases (e.g., using an informed search such as A* rather than naive BFS over the full state space).

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.

Related Interview Questions

  • Return Top K Open Businesses - Microsoft (hard)
  • Implement Memory Allocation and In-Memory Records - Microsoft (medium)
  • Implement K-Means and Detect Divisible Subarrays - Microsoft (medium)
  • Sort Three Categories In Place - Microsoft (medium)
  • Retain Top K Elements - Microsoft (medium)
Microsoft logo
Microsoft
Feb 11, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
2
0
Loading...

Problem

Given a 4×4 sliding puzzle (the classic 15-puzzle), compute the minimum number of moves required to reach the solved state, or return -1 if it is impossible.

  • The board contains numbers 1..15 and a blank represented by 0 .
  • A move consists of swapping 0 with one of its 4-directional neighbors (up/down/left/right).

Input

A 4×4 integer matrix board.

Output

An integer minMoves:

  • the minimum number of moves to reach the target state, or
  • -1 if the target state is unreachable.

Target state

1  2  3  4
5  6  7  8
9  10 11 12
13 14 15 0

Constraints/Notes

  • You must handle unsolvable configurations.
  • Aim for an approach that can finish in reasonable time for typical interview test cases (e.g., using an informed search such as A* rather than naive BFS over the full state space).

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Microsoft•More Software Engineer•Microsoft Software Engineer•Microsoft Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.