FastPrepMinimum Moves
Problems/Minimum Moves

Minimum Moves

Harness logoHarness● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A community report says this is an exact match to a well-known grid-jump minimum-moves task. The original Harness wording and screenshots were not available. The input limits, the examples, the function signature, and the rule for blocked endpoints are our choice. Our version is about 95% the same as that task.

Special thanks: 🌷 A special thank you to a lovely, amazing fren who shared that this question appeared again on October 13, 2026! (∩˃o˂∩)♡ 🩷

You are given an n x m grid maze. A cell containing 0 is open, and a cell containing 1 is an obstacle. Start at (0, 0) and reach (n - 1, m - 1).

In one move, choose up, down, left or right and a distance from 1 through k. The destination must be inside the grid, and every cell crossed, including the destination, must be open. You cannot jump over an obstacle.

Return the minimum number of moves needed, or -1 if you cannot reach the destination.

For this exercise, assume a blocked starting or destination cell makes the journey impossible. If the grid consists of one open cell, return 0.

Function

getMinimumMoves(maze: int[][], k: int) → int

Examples

Example 1

maze = [[0,0,0,0],[1,1,0,0],[0,0,0,0]]k = 2return = 3
maze
0123000001110020000

One shortest route is (0,0) → (0,2) → (2,2) → (2,3). Each move crosses only open cells and travels at most 2 cells. A two-move route cannot cover the required horizontal distance of 3 and vertical distance of 2, so the answer is 3.

Example 2

maze = [[0,0,1,0,0]]k = 4return = -1
maze
01234000100

The obstacle at (0,2) blocks the only row. A move cannot cross it, even though k is large enough to reach the final column.

Example 3

maze = [[0]]k = 1return = 0
maze
000

The starting cell is already the open destination, so no move is needed.

Constraints

  • For this exercise, assume 1 <= n, m <= 100 and 1 <= k <= 100.
  • maze is rectangular, with n rows and m columns.
  • Every cell is either 0 or 1.

More Harness interview questions

  • Choose a Road to Maximize Average Route Toll IncreasePHONE SCREEN · Seen Sep 2026
  • Encode and Decode a String StreamONSITE INTERVIEW · Seen Sep 2026
  • Streaming Ingredient DishesONSITE INTERVIEW · Seen Jul 2026

Similar questions at other companies

  • Shortest Path Around Rectangular ObstaclesDRW · OADRW interview questions
  • Minimum Knight MovesMcKinsey & Company · OAMcKinsey & Company interview questions
  • Minimum MovesGoldman Sachs · OAGoldman Sachs interview questions
  • Grid ExplorationIMC Trading · OAIMC Trading interview questions
  • Safest Shortest Path Through a GridSnowflake · OASnowflake interview questions
  • Competitive ForagingAkuna Capital · OAAkuna Capital interview questions
  • Drone Delivery with Battery Swap StationsCisco · OACisco interview questions
  • Escape the Haunted CastlePersona · OAPersona interview questions
  • Shortest Travel Time in a Grid with Traffic LightsWaymo · PHONE SCREENWaymo interview questions
  • Fire Station Response BillLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
See Harness hiring insights
Saved
class Solution {
    public int getMinimumMoves(int[][] maze, int k) {
        // Write your code here.
    }

}
Checking account…