Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.

book
Beautify Matrix

You have a 5x5 matrix consisting of 24 zeroes and a single number one. The matrix is indexed with rows from 1 to 5 (top to bottom) and columns from 1 to 5 (left to right). In one move, you can apply one of the two following transformations to the matrix:

  • Swap two neighboring rows (i.e., rows with indices i and i+1 for some integer i, where 1 ≀ i < 5).
  • Swap two neighboring columns (i.e., columns with indices j and j+1 for some integer j, where 1 ≀ j < 5).

You consider the matrix beautiful if the number one is located in the center of the matrix, at the intersection of the third row and the third column. Given a matrix, return the minimum number of moves needed to make the matrix beautiful.

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
main.cpp

main.cpp

C++

AIに質問する

expand

AIに質問する

ChatGPT

䜕でも質問するか、提案された質問の1぀を詊しおチャットを始めおください

some-alt