Can someone help me find a different and right solution? I tried to do it but it gives me the wrong answer, i found a pattern and i want to share it even if its wrong
Here comes the instructions and my interpretation... - Start from the center of the matrix. - Move in a spiral: right → down → left → up → repeat. The steps of the numbers You move 1 step in the first direction, then 1 step in the second, Then 2 steps in the next direction, 2 steps in the following, Then 3 steps, 3 steps, and so on. This is the rule you were seeing: each number “occupies” two turns before increasing.
Hope someone gets to see this (sorry if its confusing english is not my native language)
Here are some examples
Example 1: matrix1 = [ [4, 4, 4, 4, 4], [4, 2, 3, 3, 3], [4, 2, 1, 1, 3], [4, 2, 2, 1, 3], [4, 4, 4, 4, 3] ]
Btw in the center you can start with 0 too
Example 2: matrix2 = [ [2, 2, 2], [2, 1, 1], [2, 2, 1] ]
I did a code but it definitely doesnt work








Auto comment: topic has been updated by Nickarin (previous revision, new revision, compare).
I also faced the same problem as you. But if you approach it differently—by starting from any of the four corners and then moving in a consistent pattern—you can avoid unnecessary complexity. This way, you don’t need to calculate how many steps to move in each direction. Simply start moving, and whenever you can’t proceed further, switch directions using a simple
drowanddcolmethod.Thank you very much :) !