Objective: Given two dimensional matrix, write an algorithm to find out the snake sequence which has the maximum length. There could be many snake sequence in the matrix, you need to return the one with the maximum length. Travel is allowed only in two directions, either go right OR go down.

What is snake sequence: Snake sequence can be made if number in adjacent right cell or number in the adjacent down cell is either +1 or -1 from the number in the current cell.

You can travel only in two directions, either go right or go down.

All we need to take care if one extra condition that we can travel only to the adjacent cells (right or down) only if number in those cells has difference of 1 from the current cell.

Have a temporary storage , two dimensional array to store the results of snake result.

Keep tracking of maximum length and at the end print the sequence using temporary array.

We will use the Bottom-up approach of Dynamic programming and store the results of sub problems to reuse them in future.

See the recursive equation and code for better understanding.

If you find anything incorrect or you feel that there is any better approach to solve the above problem, please write comment.
__________________________________________________

This algorithm is not entirely right, it is missing the condition of checking for meeting the condition in the original matrix before print. If you run it for the following example you will see that it fails.
int arrA [][] = {{1, 2, 3, 9},
{2, 9, 2, 1},
{3, 9, 9, 2},
{4, 5, 6, 7}};