I have a matrix like this->
1 6 2
8 3 7
4 9 5
You can go any direction, up down left right diagonally and you have to find the longest sub sequence, you can select a next number in the sequence in such a way that its absolute difference is greater than 3.
Like in the case above the longest sub sequence is 1->6->2->7->3->8->4->9->5
.
I am able write a brute force code for it which finds the longest sequence which goes like finding the longest sequence for first number, second number and so on. And return the one which has the largest count.
I am new to DP. Is there any other way to solve this by using DP? I am not able to comprehend a solution using DP.