829. Minimum Moves to Spread Stones Over 3×3 Grid

HardRecursionRecursion

Given 3x3 grid (values sum=9), find min moves to make all cells=1. JSON 3x3 array.

Input: JSON 3x3 array.

Output: Integer.

Examples

Example 1
Input: [[1,1,1],[1,1,1],[1,1,1]]
Output: 0
Explanation: Already uniform.
Example 2
Input: [[3,0,1],[0,2,0],[1,0,2]]
Output: 4
Explanation: 4 moves.
Example 3
Input: [[9,0,0],[0,0,0],[0,0,0]]
Output: 20
Explanation: All at (0,0).

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →