Calculating the dp array for each possible position and calculating the max length that ends at a particular index
for ( let i of v ) { dp [ i [ 1 ] [ 1 ] ] = Math . max ( dp [ i [ 1 ] [ 1 ] ] , 1 + dp [ i [ 1 ] [ 0 ] ] ) ; } let ans = 1 ;