We’re preparing your current view and syncing the latest data.
You are given a 5x5 matrix consisting of 0s and a single 1. Your task is to calculate the minimum number of moves needed to bring the '1' to the center of the matrix (row 3, column 3). A move is defined as moving the '1' to any adjacent position (up, down, left, or right).
A 5x5 matrix of integers where each integer is either 0 or 1. There is exactly one '1' in the matrix.
An integer representing the minimum number of moves required to bring the '1' to the center position (row 3, column 3).
Matrix size is fixed at 5x5. Exactly one cell contains the value 1.
Example 1
Input
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Output
3
Explanation
The '1' is at position (2,5). The center position is (3,3). Manhattan distance = |2-3| + |5-3| = 1 + 2 = 3.