C++20 sections · 1024 units
Open in Course

Problem - Beautiful Matrix

Finding position in grid

You have a 5×55 \times 5 matrix filled with 00s and exactly one 11. The matrix becomes beautiful when the 11 is in the center position (row 33, column 33). Your task: find the minimum number of adjacent swaps needed to move the 11 to the center.

This problem tests 2D array traversal and distance calculation. You'll loop through a grid to find a target element, then compute how far it needs to move.

Count the distance.