Help me with this problem

Can we solve this by converting it into a single 1d array ?
if the matrix is:
1 2 3
4 5 6
7 8 9
Can we convert it to
1 2 3 4 5 6 7 8 9
and consider the fact that if we choose a ith index like say 1 (value =2) we can choose 3(value =4) or 5(value =5)?

Basically, You can!
If your current index is i, You can go to (\frac{i}{m}+1)\times m + one of (i\%m-1,i\%m, i\%m+1 ), Here m is the number of columns.

My question is why bother if a 2D matrix simplifies such troubles.