FastPrepMinimum Moves to Spread Stones Across a Grid
Problems/Minimum Moves to Spread Stones Across a Grid

Minimum Moves to Spread Stones Across a Grid

American Express logoAmerican Express● MediumINTERNNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an American Express online assessment for intern and new grad roles. The report clearly gives the 3 x 3 stone balancing task, moves of one cell up, down, left, or right, the goal of one stone in each cell, and the minimum number of moves. Our version is about 100% the same as the reported question.

You are given a 3 x 3 integer grid. Each value is the number of stones in that cell. The grid holds exactly 9 stones in total.

In one move, you may take one stone from a cell and put it in a neighboring cell directly above, below, left, or right of it. Return the minimum number of moves needed so that every cell holds exactly one stone.

Function

minimumMovesToSpreadStones(grid: int[][]) → int

Examples

Example 1

grid = [[1,1,0],[1,1,2],[1,1,1]]return = 1
grid
012011011122111

The middle-right cell holds an extra stone, and the top-right cell just above it is empty. Moving that stone up fixes both cells, so a single move is enough.

Example 2

grid = [[1,3,0],[1,0,0],[1,0,3]]return = 4
grid
012013011002103

The top-middle cell keeps a single stone and passes its extras to the empty cells on its right and below it. The bottom-right cell does the same with the empty cells above it and to its left. Each extra stone moves just a single step, and no stone can do better, so the answer is 4.

Example 3

grid = [[1,1,1],[1,1,1],[1,1,1]]return = 0
grid
012011111112111

Every cell already holds exactly one stone, so no moves are needed.

Constraints

  • grid.length = 3.
  • grid[i].length = 3.
  • 0 <= grid[i][j] <= 9.
  • The sum of all values in grid is exactly 9.

More American Express interview questions

  • Maximum Points in a Perimeter-Bounded RectangleOA · Seen Sep 2026
  • Largest Two Non-Overlapping Buildable SquaresOA · Seen Aug 2026
  • Maximum Sum of Two Sign-Flipping WindowsOA · Seen Aug 2026
  • Crop Text at a Whole-Word BoundaryOA · Seen Aug 2026
  • Minimum Parking Roof LengthOA · Seen Aug 2026
  • Minimum Pile Reduction StepsOA · Seen Aug 2026
  • Disjoint Target-Sum TripletsPHONE SCREEN · Seen Mar 2025

Similar questions at other companies

  • Count Eight-Neighbor Unlock PatternsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Maximum Words in Disjoint Grid PathsIndeed · PHONE SCREENIndeed interview questions
  • Count Routes Through Four Shop TypesOpenAI · OAOpenAI interview questions
  • Grid Paths with Override PassesIMC Trading · OAIMC Trading interview questions
  • Grid Paths with Override PassesMicrosoft · OAMicrosoft interview questions
  • Vehicle Builds for Required Terrain (Game Adaptation)Roblox · OARoblox interview questions
  • Maximum Profit Under a Bitwise OR LimitConcentric AI · OAConcentric AI interview questions
  • Bitwise XOR SubsequencesJP Morgan Chase · OAJP Morgan Chase interview questions
  • Beautiful Number OrderingsDocuSign · OADocuSign interview questions
  • Paint a Grid with Three ColorsIntuit · OAIntuit interview questions
All American Express interview questionsSee American Express hiring insights
Saved
class Solution {
    public int minimumMovesToSpreadStones(int[][] grid) {
        // write your code here
    }
}
Checking account…